Day 6
This commit is contained in:
parent
4e92b8544a
commit
a811664a99
5 changed files with 42 additions and 2 deletions
3
Main.hs
3
Main.hs
|
@ -7,6 +7,7 @@ import Day2
|
||||||
import Day3
|
import Day3
|
||||||
import Day4
|
import Day4
|
||||||
import Day5
|
import Day5
|
||||||
|
import Day6
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
|
@ -21,4 +22,6 @@ main = do
|
||||||
Day4.main
|
Day4.main
|
||||||
putStrLn "Day 5"
|
putStrLn "Day 5"
|
||||||
Day5.main
|
Day5.main
|
||||||
|
putStrLn "Day 6"
|
||||||
|
Day6.main
|
||||||
|
|
||||||
|
|
2
inputs/day6-test.input
Normal file
2
inputs/day6-test.input
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
Time: 7 15 30
|
||||||
|
Distance: 9 40 200
|
2
inputs/day6.input
Normal file
2
inputs/day6.input
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
Time: 45 97 72 95
|
||||||
|
Distance: 305 1062 1110 1695
|
|
@ -11,9 +11,7 @@ dependencies:
|
||||||
- bytestring
|
- bytestring
|
||||||
- matrix
|
- matrix
|
||||||
- vector
|
- vector
|
||||||
- range-set-list
|
|
||||||
- containers
|
- containers
|
||||||
- parallel
|
|
||||||
|
|
||||||
executables:
|
executables:
|
||||||
aoc23:
|
aoc23:
|
||||||
|
@ -29,3 +27,4 @@ library:
|
||||||
- Day3
|
- Day3
|
||||||
- Day4
|
- Day4
|
||||||
- Day5
|
- Day5
|
||||||
|
- Day6
|
||||||
|
|
34
src/Day6.hs
Normal file
34
src/Day6.hs
Normal 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
|
Loading…
Reference in a new issue