35 lines
850 B
Haskell
35 lines
850 B
Haskell
{-# 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
|