From 1ac9cae734f5e8c614c1b0a19fcdb3506638cc9f Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Wed, 19 Mar 2014 21:37:37 +0000 Subject: [PATCH] Move the HTML container out into a reworkable template file. --- tabulate.py | 107 ++++++++++++++++++++++++++++++-------------------- template.html | 27 +++++++++++++ 2 files changed, 91 insertions(+), 43 deletions(-) create mode 100644 template.html diff --git a/tabulate.py b/tabulate.py index 485b9b1..7130aff 100755 --- a/tabulate.py +++ b/tabulate.py @@ -81,7 +81,11 @@ def invent_dissection(n,m): assert best > 0 return dissection, this_reason -def read(n,m): +details = {} # maps (n,m) to a snippet of HTML + +def read_and_build_table_cell(n,m): + ret = "" + best = 0 # Look for appropriate file(s). @@ -122,9 +126,10 @@ def read(n,m): if best == 0: # We don't have a stored solution at all, so make up something # plausible if we can. - dissection, best_nature = invent_dissection(n, m) + dissection, auto_reason = invent_dissection(n, m) best = find_min_frag(dissection) dissections[(n,m)] = dissection + best_nature = 'a' bound, bound_type = bounds.upper_bound(n, m) @@ -139,54 +144,70 @@ def read(n,m): show_bound = "" else: tdclass = "range" - show_bound = " – %s" - sys.stdout.write("" % tdclass) - sys.stdout.write(str(best)) + show_bound = " – %s" + ret += "" % (tdclass, n, m) + ret += str(best) if show_bound != "": - sys.stdout.write(show_bound % str(bound)) - sys.stdout.write("\n") + ret += show_bound % str(bound) + ret += "\n" + + dump = "

n=%d, m=%d

\n" % (n, m, n, m) + dump += "

Best dissection known for %d into %d, with minimum fragment %s:\n" % (n, m, str(best)) + dump += "

\n" + if best == bound: + dump += "

This dissection is confidently believed optimal because an upper bound proof (%s) matches it.\n" % bound_type + elif best_nature == 'e': + dump += "

This dissection is believed optimal because it was found by an exhaustive search program, although the best upper bound proof (%s) gives an upper bound of %s.\n" % (bound_type, bound) + tdclass = "believed" + show_bound = "" + elif best_nature == 'p': + dump += "

This dissection was found by a search program which may not be exhaustive (if the conjectured denominator bound is false) and hence may not be optimal, though we think it probably is. The best upper bound proof (%s) gives an upper bound of %s.\n" % (bound_type, bound) + else: + dump += "

This dissection was found " + if best_nature == 'm': + dump += "by hand" + else: + dump += "by a simplistic automated method (%s)" % auto_reason + dump += ", and is not known to be optimal. The best upper bound proof (%s) gives an upper bound of %s.\n" % (bound_type, bound) + + details[(n, m)] = dump + + return ret def main(args): limit = 31 # FIXME: configurable - sys.stdout.write("""\ - - -Known bounds for stick-dissecting problem - - - - -""") - sys.stdout.write("\n") - sys.stdout.write("\n") + + subst = {} + + table = "
n \\ m
" + table += "\n" + table += "\n" for m in range(2,limit-1): - sys.stdout.write("\n" % m) - sys.stdout.write("\n") + table += "\n" % m + table += "\n" for n in range(2,limit): - sys.stdout.write("\n") - sys.stdout.write("\n" % n) + table += "\n" + table += "\n" % n for m in range(2,n): - read(n, m) - sys.stdout.write("\n") - sys.stdout.write("
n \\ m%d
%d
%d
%d
\n") - sys.stdout.write("\n") + table += read_and_build_table_cell(n, m) + table += "\n" + table += "\n" + subst["TABLE"] = table + + subst["DISSECTIONS"] = "".join([data for ((n, m), data) in sorted(details.items())]) + + with open("template.html") as f: + for line in f: + if line[:1] == "%" and line[-2:] == "%\n": + sys.stdout.write(subst[line[1:-2]]) + else: + sys.stdout.write(line) if __name__ == "__main__": main(sys.argv[1:]) diff --git a/template.html b/template.html new file mode 100644 index 0000000..cd6da57 --- /dev/null +++ b/template.html @@ -0,0 +1,27 @@ + + +Known bounds for stick-dissecting problem + + + +%TABLE% +%DISSECTIONS% + + -- 2.30.2