diff --git a/coco.py b/coco.py index e8cb364e046a1ad01f19cbcf104913667e08f355..8c771e0be4645793c4efd2785a5e38986d6c17c5 100755 --- a/coco.py +++ b/coco.py @@ -1,41 +1,46 @@ #!/usr/bin/python3 -running_count = [0,0,0,0,0] -def splitthem(quant): +def splitthem(quant, running_count): """ take a quantity and return False if it is not one more than equally divisible by 5 Otherwise, subtract 1 and subtract 1/5 of the remaining + + when the split is done, update the running count for whichever + first zero value """ if quant[0] % 5 != 1: return False else: - t = quant[0]//5 + share_amt = (quant[0]-1)//5 for k in range(5): if running_count[k] == 0: - running_count[k] = t + running_count[k] = share_amt break - quant[0] -= (1 + quant[0]//5) + quant[0] -= (1 + share_amt) return True -def testnum(num): +def testnum(num, running_count): """ for a given number test to see if it will succeed using the logic for split defined in splitthem 5 times. Then test to see that it is equally divisible by 5 - + When successful the running_count will be updated + one last time for the final split. """ for pers in range(5): - if not splitthem(num): + if not splitthem(num, running_count): return False if num[0] % 5 == 0: + share_amt = num[0]//5 for i in range(5): - running_count[i] += num[0]//5 + running_count[i] += share_amt + return True else: return False @@ -53,17 +58,17 @@ def main(): num = [0] for n in range(1, TESTQUANTITY): - for i in range(5): - running_count[i] = 0 + running_count = [0,0,0,0,0] num[0] = n - if testnum(num): + if testnum(num, running_count): print ("The Number Was %d" % n) print (running_count) - total = 0 - for i in running_count: - total += i - print (total) + + total = sum(running_count) + + print ("Total %d, plus 5 for the monkey!" + " Original starting count %d" % (total, n)) return print ("Not found in %d tries." % TESTQUANTITY)