diff --git a/90_Tower/lua/train.lua b/90_Tower/lua/tower.lua similarity index 97% rename from 90_Tower/lua/train.lua rename to 90_Tower/lua/tower.lua index c5e07b76..b86539a4 100644 --- a/90_Tower/lua/train.lua +++ b/90_Tower/lua/tower.lua @@ -6,10 +6,10 @@ CREATIVE COMPUTING MORRISTOWN, NEW JERSY ]] -local MAX_DISKS = 7 --"" can be used starting in Lua 5.4, as such: "local MAX_DISKS = 7" -local MAX_DISK_SIZE = 15 -local MAX_MOVES = 128 -local NUM_TOWERS = 3 +local MAX_DISKS = 7 +local MAX_DISK_SIZE = 15 +local MAX_MOVES = 128 +local NUM_TOWERS = 3 local towers = { { size = 0, elem = {} }, diff --git a/91_Train/lua/train.lua b/91_Train/lua/train.lua index 0d11e73c..dde7cd4d 100644 --- a/91_Train/lua/train.lua +++ b/91_Train/lua/train.lua @@ -8,12 +8,12 @@ print [[ math.randomseed(os.time()) -local error_margin = 5.0 +local ERROR_MARGIN = 5.0 function play() - local car_speed = math.random(40, 65) - local delta_time = math.random(5, 20) - local train_speed = math.random(20, 39) + local car_speed = math.random(40, 65) --Between 40 and 64 + local delta_time = math.random(5, 20) --Between 5 and 19 + local train_speed = math.random(20, 39) --Between 20 and 38 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) ) @@ -33,7 +33,7 @@ function play() local car_time = delta_time * train_speed / (car_speed - train_speed) local percent = ( math.abs(car_time-input) * 100 / car_time + .5) - if percent > error_margin then + if percent > ERROR_MARGIN then print( string.format("SORRY. YOU WERE OFF BY %f PERCENT.", percent) ) else print( string.format("GOOD! ANSWER WITHIN %f PERCENT.", percent) )