update train and tower Lua

This commit is contained in:
Rafael Conceição
2023-10-10 11:17:51 +01:00
parent 753327db44
commit 2aa6776dd7
2 changed files with 9 additions and 9 deletions

View File

@@ -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) )