+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
+