diff --git a/2023/day06/day06.hs b/2023/day06/day06.hs new file mode 100644 index 0000000..85f02c3 --- /dev/null +++ b/2023/day06/day06.hs @@ -0,0 +1,16 @@ +import Data.List + +main :: IO () +main = do + input <- parse <$> readFile "input" + print $ product $ map race input + print $ race (p2ify input) + +parse :: String -> [[Int]] +parse = transpose . map (map read . tail . words) . lines + +p2ify :: [[Int]] -> [Int] +p2ify = map (read . concatMap show) . transpose + +race :: [Int] -> Int +race [x,y] = length $ filter (>y) $ zipWith (*) [0..x] [x, pred x..] diff --git a/2023/day06/input b/2023/day06/input new file mode 100644 index 0000000..7c06e07 --- /dev/null +++ b/2023/day06/input @@ -0,0 +1,2 @@ +Time: 59 68 82 74 +Distance: 543 1020 1664 1022 diff --git a/2023/day06/testinput b/2023/day06/testinput new file mode 100644 index 0000000..28f5ae9 --- /dev/null +++ b/2023/day06/testinput @@ -0,0 +1,2 @@ +Time: 7 15 30 +Distance: 9 40 200