Skip to content

Instantly share code, notes, and snippets.

@sivy
Created April 23, 2011 05:43
Show Gist options
  • Select an option

  • Save sivy/938365 to your computer and use it in GitHub Desktop.

Select an option

Save sivy/938365 to your computer and use it in GitHub Desktop.
In college I had a cabinet-style folding desk, upon the top of which i started stacking all the cans of Coke I drank that quarter (it was design school!).
#!/usr/bin/env python
"""
In college I had a cabinet-style folding desk, upon the top of which i started stacking all the cans of Coke I
drank that quarter (it was design school!). I remembered that at the top of the stack (a pyramid in which the x
and y directions of each level were one less than the level below) was a 1x3 row of cans. How many in all did I
drink, if I remember the total was more then, say, 300 and less than, say 400?
"""
total=0
# the top row, at around ceiling level:
x=2
y=3
level=1
# build the pyramid from the ceiling down:
while(total + x*y < 400): # look-ahead
total += x*y
print "level %s: %s * %s (%s cans)" % (level, x,y, total)
x += 1
y += 1
level += 1
print "avg Cokes per day: %d" % (total / 90)
@sivy
Copy link
Copy Markdown
Author

sivy commented Apr 23, 2011

level 1: 2 * 3 (6 cans)
level 2: 3 * 4 (18 cans)
level 3: 4 * 5 (38 cans)
level 4: 5 * 6 (68 cans)
level 5: 6 * 7 (110 cans)
level 6: 7 * 8 (166 cans)
level 7: 8 * 9 (238 cans)
level 8: 9 * 10 (328 cans)
avg Cokes per day: 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment