This commit is contained in:
Samae 2024-01-02 19:10:03 +02:00
parent 4e92b8544a
commit a811664a99
5 changed files with 42 additions and 2 deletions

View file

@ -7,6 +7,7 @@ import Day2
import Day3
import Day4
import Day5
import Day6
main :: IO ()
main = do
@ -21,4 +22,6 @@ main = do
Day4.main
putStrLn "Day 5"
Day5.main
putStrLn "Day 6"
Day6.main

2
inputs/day6-test.input Normal file
View file

@ -0,0 +1,2 @@
Time: 7 15 30
Distance: 9 40 200

2
inputs/day6.input Normal file
View file

@ -0,0 +1,2 @@
Time: 45 97 72 95
Distance: 305 1062 1110 1695

View file

@ -11,9 +11,7 @@ dependencies:
- bytestring
- matrix
- vector
- range-set-list
- containers
- parallel
executables:
aoc23:
@ -29,3 +27,4 @@ library:
- Day3
- Day4
- Day5
- Day6

34
src/Day6.hs Normal file
View file

@ -0,0 +1,34 @@
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -Wno-unused-do-bind #-}
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
module Day6 where
main :: IO ()
main = do
putStrLn "Part 1"
inp <- parseInput <$> readFile "inputs/day6.input"
print inp
print $ part1 inp
putStrLn "Part 2"
print part2
type RaceLasts = Int
type RecordDistance = Int
distance :: Int -> Int -> Int
distance raceLasts ws = ws * (raceLasts - ws)
part1 :: [(Int, Int)] -> Int
part1 = product . map (\ (du,rd) -> length $ filter (> rd) $ map (distance du) [0..du])
--Time: 45977295
--Distance: 305106211101695
part2 :: Int
part2 = length . filter (> 305106211101695) . map (distance 45977295) $ [0..45977295]
parseInput :: String -> [(RaceLasts,RecordDistance)]
parseInput = (\ [a,b] -> zip a b)
. map (map read . tail . words)
. lines