Created
April 23, 2011 05:43
-
-
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!).
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
| #!/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) |
Author
sivy
commented
Apr 23, 2011
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment