From c46213b57944279fec8d7e910a4ff75a346dafaa Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Thu, 23 Dec 2021 11:26:56 +0000 Subject: [PATCH] Done day 20 --- advent-of-code21.cabal | 5 + advent20/Main.hs | 115 ++++++++++++++++++++++ data/advent20.txt | 102 ++++++++++++++++++++ data/advent20a.txt | 7 ++ problems/day20.html | 212 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 441 insertions(+) create mode 100644 advent20/Main.hs create mode 100644 data/advent20.txt create mode 100644 data/advent20a.txt create mode 100644 problems/day20.html diff --git a/advent-of-code21.cabal b/advent-of-code21.cabal index f92f871..7134dcd 100644 --- a/advent-of-code21.cabal +++ b/advent-of-code21.cabal @@ -201,3 +201,8 @@ executable advent19 import: common-extensions, build-directives main-is: advent19/Main.hs build-depends: linear, text, attoparsec, containers, multiset + +executable advent20 + import: common-extensions, build-directives + main-is: advent20/Main.hs + build-depends: linear, mtl, containers diff --git a/advent20/Main.hs b/advent20/Main.hs new file mode 100644 index 0000000..fbc4fb6 --- /dev/null +++ b/advent20/Main.hs @@ -0,0 +1,115 @@ +-- Writeup at https://work.njae.me.uk/2021/12/18/advent-of-code-2021-day-16/ + + +import Control.Monad.State.Strict +import Control.Monad.Reader +-- import Control.Monad.Writer +import Control.Monad.RWS.Strict +import Data.List +import Data.Ix +import Data.Maybe + +import qualified Data.Set as S +import Linear (V2(..), (^+^)) + +type Pixel = V2 Int -- row, column + +data Image = Image + { grid :: S.Set Pixel + , distantPixel :: Bool + , explicitRegion :: (Pixel, Pixel) + } deriving (Eq, Show) + +type Enhancement = [Bool] + +type ImageEnhancer = RWS Enhancement [Int] Image + +main :: IO () +main = + do text <- readFile "data/advent20.txt" + let (enhancement, image) = parse text + print $ part1 enhancement image + print $ part2 enhancement image + +-- part1 enhancement image = s +-- where (s, image', _) = runRWS (enhanceImage 2) enhancement image + +part1 enhancement image = fst $ evalRWS (enhanceImage 2) enhancement image + +part2 enhancement image = fst $ evalRWS (enhanceImage 50) enhancement image + +enhanceImage :: Int -> ImageEnhancer Int +enhanceImage 0 = do image <- get + return $ S.size $ grid image +enhanceImage n = do newImage + enhanceImage (n - 1) + +newImage :: ImageEnhancer () +newImage = + do image <- get + let region = explicitRegion image + let region' = expandRegion region + let heres = range region' + let distant = distantPixel image + newPixelStates <- mapM newPixel heres + let grid' = S.fromList $ catMaybes newPixelStates + enhancement <- ask + let distant' = if distant then (last enhancement) else (head enhancement) + put $ Image {grid = grid', distantPixel = distant', explicitRegion = region'} + + +showImage :: Image -> String +showImage image = + unlines $ [ [showPixel (V2 r c) | c <- [minC..maxC] ] | r <- [minR..maxR]] + where (V2 minR minC, V2 maxR maxC) = explicitRegion image + g = grid image + showPixel here = if here `S.member` g then '█' else ' ' + +newPixel :: Pixel -> ImageEnhancer (Maybe Pixel) +newPixel here = + do stencil <- findStencil here + let i = intify stencil + enh <- ask + return $ if enh!!i then Just here else Nothing + +findStencil :: Pixel -> ImageEnhancer [Bool] +findStencil here = + do let nbrs = map (here ^+^) neighbours + g <- gets grid + d <- gets distantPixel + r <- gets explicitRegion + return $ map (findContents g d r) nbrs + +findContents :: S.Set Pixel -> Bool -> (Pixel, Pixel) -> Pixel -> Bool +findContents grid distant region here + | inRange region here = here `S.member` grid + | otherwise = distant + + +neighbours :: [Pixel] +neighbours = [V2 r c | r <- [-1, 0, 1], c <- [-1, 0, 1]] + +expandRegion :: (Pixel, Pixel) -> (Pixel, Pixel) +expandRegion ((V2 r0 c0), (V2 r1 c1)) = (V2 (r0 - 1) (c0 - 1), V2 (r1 + 1) (c1 + 1)) + +parse text = (enhancement, image) + where ls = lines text + enhancement = [ c == '#' | c <- head ls] + image = mkImage $ drop 2 ls + + +mkImage :: [String] -> Image +mkImage rows = Image { grid = grid, distantPixel = False + , explicitRegion = ((V2 0 0), (V2 maxRow maxCol)) + } + where maxRow = length rows - 1 + maxCol = (length $ head rows) - 1 + grid = S.fromList [V2 r c | r <- [0..maxRow], c <- [0..maxCol], (rows!!r)!!c == '#'] + + +intify pixels = foldl' addBit 0 pixels + where addBit w b = (w * 2) + (if b then 1 else 0) + +-- wordify :: BS.BitString -> Integer +-- wordify bs = foldl' addBit 0 $ BS.to01List bs +-- where addBit w b = (w * 2) + (fromIntegral b) diff --git a/data/advent20.txt b/data/advent20.txt new file mode 100644 index 0000000..e1398e1 --- /dev/null +++ b/data/advent20.txt @@ -0,0 +1,102 @@ +#.#.##.#.#....#.#.#......###.#....####.#...###..#...#.#.###.#...#.#...##..#.#.#.##..#......#..#...#..#.###...####....#.#....#...#.##.#####.##..#####..###..###.#.##.#####..#..#..######..######.####.####....#.#..####..#...##..#..#.#.##.##.##.##.#.##..##..###....###.###.##..#...#.##..#.#..####.......#...###..#....##..#..##.#..##..#..##.###..##.#.##...#..###.###...###...#.#######.....#.##..#......#....#.#..##..##..#..####.#.#.##..##.##.#..#.##..#.......#.####.#.##..#..........#.#.#..##.##......##..#.##..#.####. + +.#..####..#.####.####...#.##..##.##....#..#####..#.#......##....#.#.#..####...###..#..#.#.##.##...## +#...##.......##..#....##.####.....####..#.#.....#.#.#........#.#######.#.##...####.#.#...#.###...### +###..##.#.#.#.#....##....#.#.#.##..#.##..##.##.##.#.##...##..####.....###.#.#.#.#....#......###..##. +###......#.##.....#......##..######.######.##..........#.#..#.#.########.####.###.#.#...#.##.##.##.. +.###.#.#......######.####......#..##....#..#...###...#####..####..###.#####..###...####.#.###.#.###. +#.#..##.....#...###...#.##.#..#.#.#.......#.##.###....###.###.#..###...#.#..#...#..###..##.###.##... +#####.#.##..#.##..####.....#.#.#.#....###....##.######.##...###....###.##.#...#....####.##.#.###..#. +.##...##.#....##.#..#......####.#..#.##...##...#.##.....#.#.#.###.###.##.#.##.#.###..#..#..###...... +.....#....#..#..####.####..#..#........#....#.#.##.######.#..#...##.###.#.#....#..#.#....##....##.## +..#...####.#.#.....##.#.##.#.#...##..####.#.###.#..#.###...#.#.....###....#..#..#.#########..####.## +.#..###.#.....#..#.....#.##.##..#.#####..############.#..#.#.###........#.##....#...#.#.#....#.#..## +.#.#..#####.####.#.##...#.#.##....##..#.#.#..#.#.##.##.#..##....##.##.###....#.##..#.#####..####..## +#...##......#####..##...#.....##..#..##......#.#######.#.##..###.#..###..#.#.#.#.#.###.#.##.#.####.. +##..#...####.#..#....#..#..##......##.##....##.#..#.#.##.###.#.#.....#.#..##.###.#####.#..#.#####.## +#..###.#.###.##......#.####.....####.##....#.....###.#.#######.#..##.#.###.##...###....##.#.####...# +..#.###.##.#.#.#..##..####.....#.##.##.##....##.####..#.###..####...#...#.#..##.##...#...#.#.##.#### +##...#.##.#######..##.##.#####.......#..#..##.#....#.####..#.##.##...###.#....#....#.##.##.####..##. +##...##.###.#.#.#.#.##.##....#.####.###..#..#.#.##..###.##..#.#.#.##.#####.####..###...#.....###..#. +#..#.#####...#...#...#...##.##.##..##.###..###.####.......#.#####.###..###.#.###....#.####...#.#.#.. +#######..####.#.........#.##.###.##.##..####...#....#..###.##....#.#.....##.####..##.#.##..#.#.#...# +..###.#..#.#..#.#.#..#...#.#....#..###.#.###.#..#..#...#####..#......###.#.#..#..#.#.##....#.#.#..#. +#.....###...#...###.....###....#.################.##..##..#...###.##.#....#....##.#.#.#..##.#.##..## +.#.###....##.#.##..#.#######..####....#.####.#.#.####..##.#####..#...#.#.######.###..#.##...#..##.## +..#.#.##.#.#.#......#.#...#..#...#.##.#..##.#####.###....###.####..####.#....##.#########.....##..#. +.#.##..#.##...#.##.#.##.#.#.#.##...###.##.#.#####..##.#..##.#.##.#.....#..##.##..##..#..#.#.##.##... +.#...#.##......##.#..##.#.#...#.##.##.####...###..#..###..........#.#.#.#.##.##.##.##..####..#.#.### +........###..##...##..##.#.###....#.#......##..####.#####....#...#...##.....##.##.#..#...#####...### +#..###.#.##.#.#.##.....#.###.#.###.#####.#..#.#..##..###..##.##...#...##.#...#.#..#..#.##...#.##...# +##....##...#####.....#..#..#.....##.##..#......###.##...#..#.######.#..#.######..#..#.#.....#....#.. +#...#.#..##..##.#....#.#..#...##.#####..####.###.##...#.###...#.##.#.##.#.#...###.##.####..###.#.### +.#..##.#.###..####.#..#..##.#..#.##.#.#...#.##.#.###.##..###.#.##..##..#..#.#.###.##.###.#..#..##.#. +#....#.####..##.#..#.###.####..#.######.#.##.#.###...##...#.#..#.##.##....###...#.#..#.#...#..###### +###.#..##..#######.##..#.#..#.###..##.#..####.#.###.#.#.##.#....#......#...#.#.##.#...###.#.##.#.... +.#.#####..##..#.##.....##..##.#....##.##.##..##.####.#...##..##...#...####..####.#.##...#...#....#.. +...#.###...##..##...#.#..####..#.###..###.###.......#####..##..###.##..##.#.....####....#.###.#..### +#.#..##..#####.#.##.#..####....#...#..####.#.##....#..#..#.##.##.#.##..#..#.#.#..#####..##...#.#..#. +..#..###...#.#......##########..#.....#.....#.###....###..#.#..###.#..###..#.#...#.##....###...#.#.# +#.#...#.##..#..##...#######.##.##.#####...#####..#...#....#....#..#.#.##.#...........###.##.###...## +.#..#.#.###..#....##..#..##.##..#.##..####..#...####.##..#..#####...#.###..#..##.#...##..#.#.#.###.# +###..#..#####..#....#.##....##.#...........###..##...##.##..#....##.###..##.#.#.#..#..##..###...##.. +.#...##.#.#...##.###..##.#.#.########..####.#.#.#.##.#..#.#####...#.#...####...#.##.##.###...#....#. +#####..#.#..######...#....##.#..#.##..#...#####...#....####..###.#..#..###......###.#.....###.###### +.##.#....#...#.##.#.######..#....##..#.###...##..######.#####..##.####.##...#.....###..###.##..#..## +..###.##...#.###.#..####....###....#.##.#..##..#..#.#...#.##.......####.#....##.#....#...###...#.#.. +##..##.###..#....##.##...#....#.#####.#...#.#.#.###.#.##.#####.#...##....#....##..##.##..##.##.#..## +#...###.#.#.##..........##...#..#####.#...###.##...#...###.##.##...####.##.........#.#######.#.#.#.. +..#....##...##.#.#..##.#...#.######.##.###.###..#..##.#........##..###...#.##..#######.##.....##.##. +.#.##.##.#..#...#.#.##.#..##.##..#..###.##.###.#.###..##.###.#..##.#.....###.#.#.###...#########.#.# +..#.##.#..###..##..#..##.#...#..##..##..#..#.#....#..##.#...#...##..#....#..##.#...#.##.#.########.. +#..####..####..##.#.##..####.#.#.#..#.....###.###..#....#.#####..####.#.....#...#....###.#.#.......# +.###.#...#.###..#......#..#..####.##...###...##...##...#.#..#....###......###.....#.####...##.#.##.# +##..#.#.......##..####.#..#...#.##..###...#.....##..#....#..###.......#####...##.###.#####..#..###.. +..#.#.##.#.#.##.##.####.##.#.#.......#..##.#.#.##....#.##.####..#######..##.#....#..#.##....####.... +.#..#..#........####..#.#.#.######.###.#...#.#.#..#.#......##..#.#...####..#.#.#.#..#....##.#.#..#.# +.###.#...#......###.######.#....#######..#.##...###..#.##..#..###.##.#.....#.######..##.#.#...####.. +#.#.##..###....#.....#..###..#.#.###.#...##.#.#..##.#.#####.#..##.....#.#####.#..#..##.####.##....#. +.#####....###..#..##..###.####...###..#.######..#####.##..#.####....#.#..###.#.#...#..#.#.##.#.#..## +..#####.#..#.######..#.##.##..#.##...#.####...####..#..#.###....##.#...#.##.#.#.#.#......#...##..##. +.#.#....#...#####..#.#.....#.#####..#..#..........##.#..###...#.#...#########....##.##..##.#..##..## +##....#.#...##.....##.#.#..#...####.###.......#####.#..####.#..###..##..##.#..##.#.###....#.##..#.#. +#.#..#..#.#..#.#####..#..###.#.###..##.#.#.##...####..#.#...#.##...##.####..##.###....######.#.##... +###..#.#..##.....#..##.#.#.##.##.##.##.#.##.##..###..##.....###..###.###..###.#..#....#.#......#...# +##....#.#..#.####.##......##...###.#...#.###..##.#..#.##..##...#.##.........##.####.###..######..### +####..#....##.#####.#...#.##.....#..#....######..#......###.#..##....#.#.###.###.#######.#.#....###. +#####.#.#####.###.#..#.#######.#.#.#.####.#####.####.##..#.########..###..#.#####.#.#.##..#..##...#. +#.......#....#.##.#...##.....#...#######..#.##...##.#...##.#.#.##..###.##..#.#.#..#.#.###...###..#.. +.###.##......#..#....#.#.####.#.##.##.#..##...###.#...#.#...##.###.#.###.###..#..#.#..#..#...###...# +####.#.##..##.##.#..##....##....##...#...#...#.######.#...#...##.#.##..#.##.##..##..#.##...##..##.#. +###.###.##.#...##.##....#..####.#...#.#....#######..##.#.##.###..###.#..#..#..#.##.#..###..#.####### +#.##...#########...#.#.#..##.#....##..#.#..##.#..####....##.#.#.###.#..#..#.#..##...#..###.###.#...# +##..#.##....#....####...#.#.#...###.#....##.#.###...#..#.####..##.#.###...###..###..#.##..#.##.##... +###.#.##..#.#.#.#######.####.#.####.#####...#....#..##.###..#...#.#..####..###.##.....#....##.....#. +.######..#.##.#####.#.##.#...#...#..#####....#.....#.####.###..#...#.##..###.#.##.###.#...#.#..##.#. +.#.#.##.###..#..#..###.#.#.#.#####..##.#...#..#.....#.###....####..#.#..#.#......#.##.#.###.#...#... +#####..#.##..####.###...##...#.###..#.##.###..####..####.#.###########.##.#...###.###.######..#..#.# +.##.#.##...#.##.##.#.##..#..##.##..#....#.#.##.##.....#.#.#..#..####.###.#..#..###.....#.###...##.#. +#####....###...#..#..##.#..#..#.##.#.#.#..##.##.####.###..###.#.#.##..##.#...###.#..#.##.#.#.#.#..## +####...#.##...##.#.....#...#####.##...###.#.#.#.#..##.#...#.#..#.#.###...#.##.#...#..###.##.####.... +##.####.#.##.###..#...#..####.###....###.#.#.####.#..##.#.#.#.##.#.#####.##..#..##.#.#######...#..## +.....#...#.#####...#........#.#...####.#.#.#.#.#..##.#.##.##.........#...###...###.#.....#...#....## +......##.#####..##...##.####.#.###.##..#.#..#..##.####....###.#.......#.##...#...#.###.##.#.#####..# +....##.###..#####.##.#..####.#.....#.##.###.##..#######.###..##...#...##....###.##..###...#.....#..# +####.#.#....##...####..#.#.#.##..#.#.#.....#...#.#.##.#..##......###.#...##...######..#####.#....### +##..#......#..##.###...#..#.#..###.###.##...####.....#.#...#..##....#...#.#...##....#..##......##.#. +#..###....##.###.##.#......#.....###...#..#####..###..#..#.#.##..#.##....###..##.#...####..##.#####. +...##..#.###..#...##.##.###.###.#....#.###.####.#...#.#####.##.#...#..##.####.#.##.#.#...#.#..#.#..# +.#......#####..#..###.###.......#.##.#..#....##.###.##.#....##.#.#######..##..#....#..#.###.##.##### +...#..##..#..####.###...#...##..####.#####..#..###...##.##.##...#..#.###...##.#....#.####..##..#.### +####.#.#..##..###..#...###...##...#.#####.###.#.#..#.##..##...##..###.....###.##.###....#..##.###..# +#.###.######..#.#..###..##....####.###.###.###.#####..###.#.#..###.#.####.###...##.##.###..##.#.#.#. +####.....#......#......#.#.#####.#...#..#.##...#####..#..########..#####.##..###...####..#..#.#.#.## +..#...#...#####...##.#.#.#..##..#..#.#......##.#####...#...###..###...#.####.#.#.#.#.#.....#..##.### +.###...#...#.###.#.#...#..##..#..###.###.#.#..##..#.....##...##.####...###..#.....#.##...##..#.##... +###...####.#.#......#####.#.##.#####.#.#####...##.##..#...#.####..#..##.#.##.#...#..#.#.#.#.#.###..# +....#####.###.##..#.#..#####..###..#..###..###..#...####.####.##..####.##..#.#.###.###..###..######. +##.##..#....#.#..#.##.##.###....#.#########.#.#...#..###.#..###..#....##.#..#.##..###.###.#...##.... +#.##.##.###.....####.###.#.#...#####..#.##.###.##.#....##.##.###.#...#.###..#..##.####.#...#...##... +.....#####.........#..#..#...##....#....###.#.###.#######..##....###.##.........###.#.##..##...###.. +..###..####.##.#.#..##..#..#.#.##.####...##..#..###...#......#..######.####....###.#.###.#.##.##.#.. +.####.#####.##.#.####......###....#.#......#.#.##...##...#..#.#..##...#..##.#...##..###.###.##.##.## \ No newline at end of file diff --git a/data/advent20a.txt b/data/advent20a.txt new file mode 100644 index 0000000..000a554 --- /dev/null +++ b/data/advent20a.txt @@ -0,0 +1,7 @@ +..#.#..#####.#.#.#.###.##.....###.##.#..###.####..#####..#....#..#..##..###..######.###...####..#..#####..##..#.#####...##.#.#..#.##..#.#......#.###.######.###.####...#.##.##..#..#..#####.....#.#....###..#.##......#.....#..#..#..##..#...##.######.####.####.#.#...#.......#..#.#.#...####.##.#......#..#...##.#.##..#...##.#.##..###.#......#.#.......#.#.#.####.###.##...#.....####.#..#..#.##.#....##..#.####....##...##..#...#......#.#.......#.......##..####..#...#.#.#...##..#.#..###..#####........#..####......#..# + +#..#. +#.... +##..# +..#.. +..### \ No newline at end of file diff --git a/problems/day20.html b/problems/day20.html new file mode 100644 index 0000000..ebfc7d9 --- /dev/null +++ b/problems/day20.html @@ -0,0 +1,212 @@ + + + + +Day 20 - Advent of Code 2021 + + + + + + + +

Advent of Code

Neil Smith (AoC++) 40*

   var y=2021;

+ + + +
+ +

--- Day 20: Trench Map ---

With the scanners fully deployed, you turn their attention to mapping the floor of the ocean trench.

+

When you get back the image from the scanners, it seems to just be random noise. Perhaps you can combine an image enhancement algorithm and the input image (your puzzle input) to clean it up a little.

+

For example:

+
..#.#..#####.#.#.#.###.##.....###.##.#..###.####..#####..#....#..#..##..##
+#..######.###...####..#..#####..##..#.#####...##.#.#..#.##..#.#......#.###
+.######.###.####...#.##.##..#..#..#####.....#.#....###..#.##......#.....#.
+.#..#..##..#...##.######.####.####.#.#...#.......#..#.#.#...####.##.#.....
+.#..#...##.#.##..#...##.#.##..###.#......#.#.......#.#.#.####.###.##...#..
+...####.#..#..#.##.#....##..#.####....##...##..#...#......#.#.......#.....
+..##..####..#...#.#.#...##..#.#..###..#####........#..####......#..#
+
+#..#.
+#....
+##..#
+..#..
+..###
+
+

The first section is the image enhancement algorithm. It is normally given on a single line, but it has been wrapped to multiple lines in this example for legibility. The second section is the input image, a two-dimensional grid of light pixels (#) and dark pixels (.).

+

The image enhancement algorithm describes how to enhance an image by simultaneously converting all pixels in the input image into an output image. Each pixel of the output image is determined by looking at a 3x3 square of pixels centered on the corresponding input image pixel. So, to determine the value of the pixel at (5,10) in the output image, nine pixels from the input image need to be considered: (4,9), (4,10), (4,11), (5,9), (5,10), (5,11), (6,9), (6,10), and (6,11). These nine input pixels are combined into a single binary number that is used as an index in the image enhancement algorithm string.

+

For example, to determine the output pixel that corresponds to the very middle pixel of the input image, the nine pixels marked by [...] would need to be considered:

+
# . . # .
+#[. . .].
+#[# . .]#
+.[. # .].
+. . # # #
+
+

Starting from the top-left and reading across each row, these pixels are ..., then #.., then .#.; combining these forms ...#...#.. By turning dark pixels (.) into 0 and light pixels (#) into 1, the binary number 000100010 can be formed, which is 34 in decimal.

+

The image enhancement algorithm string is exactly 512 characters long, enough to match every possible 9-bit binary number. The first few characters of the string (numbered starting from zero) are as follows:

+
0         10        20        30  34    40        50        60        70
+|         |         |         |   |     |         |         |         |
+..#.#..#####.#.#.#.###.##.....###.##.#..###.####..#####..#....#..#..##..##
+
+

In the middle of this first group of characters, the character at index 34 can be found: #. So, the output pixel in the center of the output image should be #, a light pixel.

+

This process can then be repeated to calculate every pixel of the output image.

+

Through advances in imaging technology, the images being operated on here are infinite in size. Every pixel of the infinite output image needs to be calculated exactly based on the relevant pixels of the input image. The small input image you have is only a small region of the actual infinite input image; the rest of the input image consists of dark pixels (.). For the purposes of the example, to save on space, only a portion of the infinite-sized input and output images will be shown.

+

The starting input image, therefore, looks something like this, with more dark pixels (.) extending forever in every direction not shown here:

+
...............
+...............
+...............
+...............
+...............
+.....#..#......
+.....#.........
+.....##..#.....
+.......#.......
+.......###.....
+...............
+...............
+...............
+...............
+...............
+
+

By applying the image enhancement algorithm to every pixel simultaneously, the following output image can be obtained:

+
...............
+...............
+...............
+...............
+.....##.##.....
+....#..#.#.....
+....##.#..#....
+....####..#....
+.....#..##.....
+......##..#....
+.......#.#.....
+...............
+...............
+...............
+...............
+
+

Through further advances in imaging technology, the above output image can also be used as an input image! This allows it to be enhanced a second time:

+
...............
+...............
+...............
+..........#....
+....#..#.#.....
+...#.#...###...
+...#...##.#....
+...#.....#.#...
+....#.#####....
+.....#.#####...
+......##.##....
+.......###.....
+...............
+...............
+...............
+
+

Truly incredible - now the small details are really starting to come through. After enhancing the original input image twice, 35 pixels are lit.

+

Start with the original input image and apply the image enhancement algorithm twice, being careful to account for the infinite size of the images. How many pixels are lit in the resulting image?

+
+

Your puzzle answer was 5225.

--- Part Two ---

You still can't quite make out the details in the image. Maybe you just didn't enhance it enough.

+

If you enhance the starting input image in the above example a total of 50 times, 3351 pixels are lit in the final output image.

+

Start again with the original input image and apply the image enhancement algorithm 50 times. How many pixels are lit in the resulting image?

+
+

Your puzzle answer was 18131.

Both parts of this puzzle are complete! They provide two gold stars: **

+

At this point, you should return to your Advent calendar and try another puzzle.

+

If you still want to see it, you can get your puzzle input.

+

You can also this puzzle.

+
+ + + + + + \ No newline at end of file -- 2.34.1