From 25b3132348e1f5964f4ec4bc4e1226f21d14bb3f Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 16 Mar 2014 18:05:15 +0000 Subject: [PATCH] Script to tabulate results as a web page. Marks places where bounds aren't tight. --- tabulate.py | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100755 tabulate.py diff --git a/tabulate.py b/tabulate.py new file mode 100755 index 0000000..16a23c8 --- /dev/null +++ b/tabulate.py @@ -0,0 +1,92 @@ +#!/usr/bin/env python + +import sys, os, re, fractions +from fractions import Fraction + +import bounds + +header_re = re.compile(r'^(\d+) into (\d+).*:.* ([\d/]+)') + +def read(n,m): + best = 0 + + # Look for appropriate file(s). + for filename, nature in [("data/main.%d.%d" % (n,m), "e"), + ("data/partition.%d.%d" % (n,m), "p"), + ("data/manual.%d.%d" % (n,m), "m")]: + if os.path.exists(filename): + with open(filename) as f: + header = f.readline() + match = header_re.match(header) + assert match is not None + assert int(match.group(1)) == n + assert int(match.group(2)) == m + this_best = Fraction(match.group(3)) + if this_best > best: + best = this_best + best_nature = nature + + bound, bound_type = bounds.upper_bound(n, m) + + if best == bound: + tdclass = "known" + show_bound = "" + elif best_nature == 'e': + tdclass = "believed" + show_bound = "" + elif best_nature == 'p': + tdclass = "probable" + show_bound = " (– %s)" + else: + tdclass = "range" + show_bound = " – %s" + sys.stdout.write("" % tdclass) + sys.stdout.write(str(best)) + if show_bound != "": + sys.stdout.write(show_bound % str(bound)) + sys.stdout.write("\n") + +def main(args): + limit = 18 # FIXME: configurable + sys.stdout.write("""\ + + +Known bounds for stick-dissecting problem + + + + +""") + sys.stdout.write("\n") + sys.stdout.write("\n") + for m in range(2,limit-1): + sys.stdout.write("\n" % m) + sys.stdout.write("\n") + for n in range(2,limit): + sys.stdout.write("\n") + sys.stdout.write("\n" % n) + for m in range(2,n): + read(n, m) + sys.stdout.write("\n") + sys.stdout.write("
n \\ m%d
%d
\n") + sys.stdout.write("\n") + +if __name__ == "__main__": + main(sys.argv[1:]) -- 2.30.2