diff --git a/haskell/Puzzles/Day7.hs b/haskell/Puzzles/Day7.hs index e6e2047..278dd28 100644 --- a/haskell/Puzzles/Day7.hs +++ b/haskell/Puzzles/Day7.hs @@ -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 } diff --git a/outputs/real/7/2 b/outputs/real/7/2 new file mode 100644 index 0000000..aceb0b7 --- /dev/null +++ b/outputs/real/7/2 @@ -0,0 +1 @@ +18818811755665 \ No newline at end of file