2019 day 8: parts 1 & 2
This commit is contained in:
@@ -43,10 +43,57 @@ would like you to find the layer that contains the /fewest =0= digits/.
|
||||
On that layer, what is /the number of =1= digits multiplied by the
|
||||
number of =2= digits?/
|
||||
|
||||
To begin, [[file:8/input][get your puzzle input]].
|
||||
Your puzzle answer was =2250=.
|
||||
|
||||
Answer:
|
||||
** --- Part Two ---
|
||||
Now you're ready to decode the image. The image is rendered by stacking
|
||||
the layers and aligning the pixels with the same positions in each
|
||||
layer. The digits indicate the color of the corresponding pixel: =0= is
|
||||
black, =1= is white, and =2= is transparent.
|
||||
|
||||
You can also [Shareon
|
||||
[[https://twitter.com/intent/tweet?text=%22Space+Image+Format%22+%2D+Day+8+%2D+Advent+of+Code+2019&url=https%3A%2F%2Fadventofcode%2Ecom%2F2019%2Fday%2F8&related=ericwastl&hashtags=AdventOfCode][Twitter]]
|
||||
[[javascript:void(0);][Mastodon]]] this puzzle.
|
||||
The layers are rendered with the first layer in front and the last layer
|
||||
in back. So, if a given position has a transparent pixel in the first
|
||||
and second layers, a black pixel in the third layer, and a white pixel
|
||||
in the fourth layer, the final image would have a /black/ pixel at that
|
||||
position.
|
||||
|
||||
For example, given an image =2= pixels wide and =2= pixels tall, the
|
||||
image data =0222112222120000= corresponds to the following image layers:
|
||||
|
||||
#+BEGIN_EXAMPLE
|
||||
Layer 1: 02
|
||||
22
|
||||
|
||||
Layer 2: 11
|
||||
22
|
||||
|
||||
Layer 3: 22
|
||||
12
|
||||
|
||||
Layer 4: 00
|
||||
00
|
||||
#+END_EXAMPLE
|
||||
|
||||
Then, the full image can be found by determining the top visible pixel
|
||||
in each position:
|
||||
|
||||
- The top-left pixel is /black/ because the top layer is =0=.
|
||||
- The top-right pixel is /white/ because the top layer is =2=
|
||||
(transparent), but the second layer is =1=.
|
||||
- The bottom-left pixel is /white/ because the top two layers are =2=,
|
||||
but the third layer is =1=.
|
||||
- The bottom-right pixel is /black/ because the only visible pixel in
|
||||
that position is =0= (from layer 4).
|
||||
|
||||
So, the final image looks like this:
|
||||
|
||||
#+BEGIN_EXAMPLE
|
||||
01
|
||||
10
|
||||
#+END_EXAMPLE
|
||||
|
||||
/What message is produced after decoding your image?/
|
||||
|
||||
Your puzzle answer was =FHJUL=.
|
||||
|
||||
Both parts of this puzzle are complete! They provide two gold stars: **
|
||||
|
Reference in New Issue
Block a user