Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Haskell playground created by essic - https://repl.it/J0S6/16
race :: Int -> Int -> Int -> Maybe (Int, Int, Int)
race v1 v2 g
| v1 >= v2 = Nothing
| otherwise =
let ts = convertToSecondsThenFloorIt $ calculateTimeToCatchUpInHours v1 v2 g
h = getHours ts
m = getMinutes ts
s = getSeconds ts
in Just (h, m, s)
where
calculateTimeToCatchUpInHours speed1 spped2 lead =
(/) (fromIntegral lead) (fromIntegral (spped2 - speed1))
convertToSecondsThenFloorIt =
floor . (* 3600)
getHours = (`div` 3600)
getMinutes = (`div` 60) . (`rem` 3600)
getSeconds = (`rem` 60) . (`rem` 3600)
main :: IO ()
main = putStrLn . show $ race 720 850 70
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.