Solve day 7 part 2

This commit is contained in:
George Thomas 2025-12-08 16:49:57 +00:00
parent 423ad9821c
commit f12e7b6e36
2 changed files with 14 additions and 0 deletions

View File

@ -2,6 +2,7 @@ module Puzzles.Day7 (puzzle) where
import Pre
import Data.IntMap qualified as IM
import Data.IntSet qualified as IS
import Data.Text.Lazy qualified as TL
@ -28,6 +29,18 @@ puzzle =
pure if hit then [x - 1, x + 1] else [x]
)
(IS.singleton start)
, uncurry \start ->
TL.show
. sum
. map snd
. IM.toList
. foldl
( \beams splitters ->
IM.fromListWith (+) . concat $ flip map (IM.toList beams) \(x, n) -> do
let hit = x `IS.member` splitters
zip (if hit then [x - 1, x + 1] else [x]) (repeat n)
)
(IM.singleton start (1 :: Int))
]
, extraTests = mempty
}

1
outputs/real/7/2 Normal file
View File

@ -0,0 +1 @@
18818811755665