chiark / gitweb /
Invent a dissection if none is stored.
authorSimon Tatham <anakin@pobox.com>
Mon, 17 Mar 2014 18:34:57 +0000 (18:34 +0000)
committerSimon Tatham <anakin@pobox.com>
Mon, 17 Mar 2014 18:34:57 +0000 (18:34 +0000)
This will help to fill in the cells for which neither search program
completed in a reasonable time.

tabulate.py

index d06e186..564261c 100755 (executable)
@@ -41,6 +41,26 @@ def verify(n, m, dissection):
     assert total == n
     assert collections[0] == collections[1]
 
+def gcd_dissector(n,m):
+    gcd = fractions.gcd(n,m)
+    return [[(m, (gcd,) * (n/gcd))],
+            [(n, (gcd,) * (m/gcd))]]
+
+def invent_dissection(n,m):
+    # Try to come up with a dissection by assorted simple methods.
+    best = 0
+    for dissector, this_reason in [
+        (gcd_dissector, "trivial gcd solution"),
+        ]:
+        dissection = dissector(n, m)
+        if dissection is None: continue
+        verify(n, m, dissection)
+        this_best = find_min_frag(dissection)
+        if best < this_best:
+            best, best_reason = this_best, this_reason
+    assert best > 0
+    return dissection, this_reason
+
 def read(n,m):
     best = 0
 
@@ -79,6 +99,13 @@ def read(n,m):
                     best = this_best
                     best_nature = nature
 
+    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)
+        best = find_min_frag(dissection)
+        dissections[(n,m)] = dissection
+
     bound, bound_type = bounds.upper_bound(n, m)
 
     if best == bound:
@@ -100,7 +127,7 @@ def read(n,m):
     sys.stdout.write("</td>\n")
 
 def main(args):
-    limit = 18 # FIXME: configurable
+    limit = 24 # FIXME: configurable
     sys.stdout.write("""\
 <html>
 <head>