Created
July 19, 2012 05:14
-
-
Save shakesoda/3140918 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
| -- size 3 | |
| -- going up 1 3 5 | |
| -- going down 5 3 4 4 1 2 2 3 3 | |
| -- size 5 | |
| -- going up 1 3 5 7 9 | |
| -- going down 9 7 8 8 5 6 6 7 7 3 4 4 5 5 1 2 2 3 3 4 4 | |
| -- string.format is quite a bit of typing | |
| _ = string.format; | |
| (function(height) | |
| local count = 0 | |
| -- increment + print the current step | |
| local function step() | |
| count = count + 1 | |
| return count | |
| end | |
| print (_("Elevator shaft height: %d blocks", height)) | |
| print "Calculating steps..." | |
| print "Going up!" | |
| for i=0,height-1 do | |
| print (_("Step %d = %d", step(), i*2+1)) | |
| end | |
| print "Going down!" | |
| local max = math.pow(height,2) | |
| for i=1,max do | |
| -- lua doesn't like me iterating in reverse, apparently | |
| local action = max - i+1 | |
| print (_("Step %d = %d", step(), action/2+1)) | |
| end | |
| end)(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment