mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-25 04:15:45 -08:00
update train and tower Lua
This commit is contained in:
@@ -8,12 +8,12 @@ print [[
|
||||
|
||||
math.randomseed(os.time())
|
||||
|
||||
local error_margin = 5.0
|
||||
local ERROR_MARGIN <const> = 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) )
|
||||
|
||||
Reference in New Issue
Block a user