From 3c0963531c095bb8885cc0aae7708110d16b109a Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Mon, 6 Sep 2021 00:19:29 +0100 Subject: - Added guest contribution by Ulrich Rieke. --- challenge-128/ulrich-rieke/haskell/ch-2.hs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 challenge-128/ulrich-rieke/haskell/ch-2.hs diff --git a/challenge-128/ulrich-rieke/haskell/ch-2.hs b/challenge-128/ulrich-rieke/haskell/ch-2.hs new file mode 100644 index 0000000000..33e0f595af --- /dev/null +++ b/challenge-128/ulrich-rieke/haskell/ch-2.hs @@ -0,0 +1,23 @@ +module Challenge128_2 + where +import Data.List ( (!!) ) +import Data.List.Split ( splitOn ) + +toMinutes :: String -> Int +toMinutes time = (60 * (list !! 0 )) + ( list !! 1 ) +where + list :: [ Int ] + list = map read $ splitOn ":" time + +findTrainsInStation :: [String] -> [String] -> [Int] +findTrainsInStation arrivals departures = map (\i -> length $ filter ( > +( toMinutes $ arrivals !! i )) $ take i departuretimes ) [1..l - 1] +where + l :: Int + l = length arrivals + departuretimes :: [ Int ] + departuretimes = map toMinutes departures + +solution :: [String] -> [String] -> Int +solution arrivals departures = ( maximum $ findTrainsInStation arrivals +departures ) + 1 -- cgit