From b9397466322c94a6959140b2eb86680effdad907 Mon Sep 17 00:00:00 2001
From: Absinthe <bradley_small@hotmail.com>
Date: Fri, 20 Sep 2019 07:26:42 -0400
Subject: [PATCH] adding running count logic

---
 coco.py | 37 +++++++++++++++++++++----------------
 1 file changed, 21 insertions(+), 16 deletions(-)

diff --git a/coco.py b/coco.py
index e8cb364..8c771e0 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)
-- 
GitLab