~rootmos/AoC

2bc4c2cecf1d20feee305f911281668d5883ef2b — Gustav Behm a month ago 33a1d6d
Add solution to AoC 2023 #06b
1 files changed, 7 insertions(+), 6 deletions(-)

M 2023/06.hs
M 2023/06.hs => 2023/06.hs +7 -6
@@ 29,16 29,17 @@ parser = do
  ds <- many $ int <* spaces
  return $ zip ts ds

naive (t, r) = length $ filter (>r) $ take (t+1) [0..] <&> \h -> h * (t - h)

partA :: Parse -> Int
partA rs = foldr (*) 1 $ fmap f rs
  where f (t, r) = length $ filter (>r) $ take (t+1) [0..] <&> \h -> h * (t - h)
partA rs = foldr (*) 1 $ fmap naive rs

--partB :: Parse -> Parse
--partB = id
partB :: Parse -> Int
partB rs = naive $ (\(t, d) -> (read t, read d)) $ foldr (\(t1, d1) (t0, d0) -> (t1++t0, d1++d0)) ("", "") $ fmap (\(t, d) -> (show t, show d)) rs

main :: IO ()
main = with parser $ do
  run "06.example" "a example" partA
  run "06.input" "a input" partA
  --run "06.example" "b example" partB
  --run "06.input" "b input" partB
  run "06.example" "b example" partB
  run "06.input" "b input" partB