Created
August 1, 2013 21:06
-
-
Save shurane/6135325 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def m(n): | |
""" | |
m(0) is undefined | |
""" | |
bowls = [1 for bowl in xrange(n)] | |
index=0 | |
counter=0 | |
while True: | |
counter +=1 | |
index = bowls_distribute(bowls,index) | |
#print index, bowls | |
if bowls_allone(bowls): | |
break | |
return counter | |
def bowls_distribute(bowls, index=0): | |
current=index | |
for bean in xrange(bowls[index]): | |
current += 1 | |
current = current % len(bowls) | |
bowls[index] -= 1 | |
bowls[current] +=1 | |
return current | |
def bowls_allone(bowls): | |
for bowl in bowls: | |
if bowl != 1: | |
return False | |
return True | |
print m(5) | |
print m(100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment