From: Simon Tatham Date: Fri, 14 Mar 2014 22:58:47 +0000 (+0000) Subject: Add a -v option. X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=0917331168d079acc8bd6901289acdafe9459f56;p=matchsticks-search.git Add a -v option. --- diff --git a/partition.py b/partition.py index d0c0dd6..c8c7db7 100755 --- a/partition.py +++ b/partition.py @@ -1,11 +1,13 @@ #!/usr/bin/env python -import sys, subprocess, math +import sys, subprocess, math, getopt from fractions import Fraction +verbose = False def vprint(*args): # In verbose mode, print diagnostics. - pass # FIXME: implement verbose mode + if verbose: + sys.stdout.write(" ".join(map(str,args)) + "\n") def find_partitions(n, minfrag, maxfrag=None, prefix=(), ret=None): """Find all partitions of n into integer pieces at least minfrag. @@ -145,7 +147,14 @@ def search_and_report(n, m): print " %d x (%s)" % (count, " + ".join([str(Fraction(k,d)) for k in col])) def main(): - m, n = sorted(map(int,sys.argv[1:3])) + global verbose + opts, args = getopt.gnu_getopt(sys.argv[1:], "v") + for opt, val in opts: + if opt == "-v": + verbose = True + else: + assert False, "unrecognised option '%s'" % opt + m, n = sorted(map(int,args[:2])) search_and_report(n, m) if __name__ == "__main__":