Created
October 21, 2013 07:13
-
-
Save fredyr/7079781 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
rows = 3 | |
glasses = [ | |
0.0, | |
0.0, 0.0, | |
0.0, 0.0, 0.0, | |
0.0, 0.0, 0.0, 0.0 ] | |
def index(i, j): | |
"ith glass in the jth row" | |
return i + sum(range(1, j+1)) | |
def dist(v, i, j): | |
idx = index(i, j) | |
glasses[idx] += v | |
if j <= rows: | |
if glasses[idx] > 1.0: | |
of = glasses[idx] - 1.0 | |
glasses[idx] = 1.0 | |
dist(of/2, i, j+1) | |
dist(of/2, i+1, j+1) | |
dist(8, 0, 0) | |
print glasses | |
print glasses[index(3,3)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment