Skip to content

Instantly share code, notes, and snippets.

@essic
Last active October 11, 2017 14:44
Show Gist options
  • Save essic/c96a1490fc3f1c411a77ed6539ae15c3 to your computer and use it in GitHub Desktop.
Save essic/c96a1490fc3f1c411a77ed6539ae15c3 to your computer and use it in GitHub Desktop.
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