diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-09-06 00:19:29 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-09-06 00:19:29 +0100 |
| commit | 3c0963531c095bb8885cc0aae7708110d16b109a (patch) | |
| tree | 5b49b79c36dbd2cd1c52cd60d7b5b436852123f2 | |
| parent | 2cca219df0eca783032f6e027dea5f1a075da8b5 (diff) | |
| download | perlweeklychallenge-club-3c0963531c095bb8885cc0aae7708110d16b109a.tar.gz perlweeklychallenge-club-3c0963531c095bb8885cc0aae7708110d16b109a.tar.bz2 perlweeklychallenge-club-3c0963531c095bb8885cc0aae7708110d16b109a.zip | |
- Added guest contribution by Ulrich Rieke.
| -rw-r--r-- | challenge-128/ulrich-rieke/haskell/ch-2.hs | 23 |
1 files changed, 23 insertions, 0 deletions
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 |
