3 import sys, os, re, fractions
4 from fractions import Fraction
8 header_re = re.compile(r'^(\d+) into (\d+).*:.* ([\d/]+)')
13 # Look for appropriate file(s).
14 for filename, nature in [("data/main.%d.%d" % (n,m), "e"),
15 ("data/partition.%d.%d" % (n,m), "p"),
16 ("data/manual.%d.%d" % (n,m), "m")]:
17 if os.path.exists(filename):
18 with open(filename) as f:
20 match = header_re.match(header)
21 assert match is not None
22 assert int(match.group(1)) == n
23 assert int(match.group(2)) == m
24 this_best = Fraction(match.group(3))
29 bound, bound_type = bounds.upper_bound(n, m)
34 elif best_nature == 'e':
37 elif best_nature == 'p':
39 show_bound = " (– %s)"
42 show_bound = " – %s"
43 sys.stdout.write("<td class=\"%s\">" % tdclass)
44 sys.stdout.write(str(best))
46 sys.stdout.write(show_bound % str(bound))
47 sys.stdout.write("</td>\n")
50 limit = 18 # FIXME: configurable
54 <title>Known bounds for stick-dissecting problem</title>
55 <style type="text/css">
57 border: 1px solid black;
58 border-collapse: collapse;
61 background-color: #00ff00;
64 background-color: #44ff44;
67 background-color: #88ff88;
70 background-color: #ff8888;
77 sys.stdout.write("<tr>\n")
78 sys.stdout.write("<th>n \\ m</th>\n")
79 for m in range(2,limit-1):
80 sys.stdout.write("<th>%d</th>\n" % m)
81 sys.stdout.write("</tr>\n")
82 for n in range(2,limit):
83 sys.stdout.write("<tr>\n")
84 sys.stdout.write("<th>%d</th>\n" % n)
87 sys.stdout.write("</tr>\n")
88 sys.stdout.write("</table>\n")
89 sys.stdout.write("</body></html>\n")
91 if __name__ == "__main__":