Skip to content

Commit 2aa6776

Browse files
committed
update train and tower Lua
1 parent 753327d commit 2aa6776

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

90_Tower/lua/train.lua renamed to 90_Tower/lua/tower.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ CREATIVE COMPUTING MORRISTOWN, NEW JERSY
66
77
]]
88

9-
local MAX_DISKS = 7 --"<const>" can be used starting in Lua 5.4, as such: "local MAX_DISKS <const> = 7"
10-
local MAX_DISK_SIZE = 15
11-
local MAX_MOVES = 128
12-
local NUM_TOWERS = 3
9+
local MAX_DISKS <const> = 7
10+
local MAX_DISK_SIZE <const> = 15
11+
local MAX_MOVES <const> = 128
12+
local NUM_TOWERS <const> = 3
1313

1414
local towers = {
1515
{ size = 0, elem = {} },

91_Train/lua/train.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ print [[
88

99
math.randomseed(os.time())
1010

11-
local error_margin = 5.0
11+
local ERROR_MARGIN <const> = 5.0
1212

1313
function play()
14-
local car_speed = math.random(40, 65)
15-
local delta_time = math.random(5, 20)
16-
local train_speed = math.random(20, 39)
14+
local car_speed = math.random(40, 65) --Between 40 and 64
15+
local delta_time = math.random(5, 20) --Between 5 and 19
16+
local train_speed = math.random(20, 39) --Between 20 and 38
1717

1818
print( string.format("\nA CAR TRAVELING AT %u MPH CAN MAKE A CERTAIN TRIP IN %u HOURS LESS THAN A TRAIN TRAVELING AT %u MPH.", car_speed, delta_time, train_speed) )
1919

@@ -33,7 +33,7 @@ function play()
3333
local car_time = delta_time * train_speed / (car_speed - train_speed)
3434
local percent = ( math.abs(car_time-input) * 100 / car_time + .5)
3535

36-
if percent > error_margin then
36+
if percent > ERROR_MARGIN then
3737
print( string.format("SORRY. YOU WERE OFF BY %f PERCENT.", percent) )
3838
else
3939
print( string.format("GOOD! ANSWER WITHIN %f PERCENT.", percent) )

0 commit comments

Comments
 (0)