Skip to content

Instantly share code, notes, and snippets.

@fredyr
Created October 21, 2013 07:13
Show Gist options
  • Save fredyr/7079781 to your computer and use it in GitHub Desktop.
Save fredyr/7079781 to your computer and use it in GitHub Desktop.
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