Last active
October 11, 2017 14:44
-
-
Save essic/c96a1490fc3f1c411a77ed6539ae15c3 to your computer and use it in GitHub Desktop.
Haskell playground created by essic - https://repl.it/J0S6/16
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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