chiark / gitweb /
Fix a bug causing some solutions to be missed, e.g. (16,5).
authorSimon Tatham <anakin@pobox.com>
Fri, 14 Mar 2014 22:53:21 +0000 (22:53 +0000)
committerSimon Tatham <anakin@pobox.com>
Fri, 14 Mar 2014 22:59:39 +0000 (22:59 +0000)
One of these days I'll remember that you have to say
range(start,end-1,-1) not range(start,end,-1) to iterate down
to and including 'end' in Python.

partition.py

index c8c7db74d9dae4c188b00c193fd1a6a5bbd73bdc..18a3a3b09ad4f862933cd19e48459d5f7f80e996 100755 (executable)
@@ -128,7 +128,7 @@ def search(n, m):
         return (m, 1, {(m,):n}, {(m,)*(n/m):m})
     best = (0,)
     for d in xrange(1, n+1):
-        for k in xrange(m*d/2, int(math.ceil(best[0]*d)), -1):
+        for k in xrange(m*d/2, int(math.ceil(best[0]*d))-1, -1):
             result = try_one_minfrag(n, m, k, d)
             if result is not None:
                 best = (Fraction(k, d), d) + result