aoc-2019-c

Advent of Code 2019 Solutions in C
git clone https://git.sinitax.com/sinitax/aoc-2019-c
Log | Files | Refs | README | sfeed.txt

part1 (1914B)


      1--- Day 8: Space Image Format ---
      2
      3The Elves' spirits are lifted when they realize you have an opportunity to reboot one of their Mars
      4rovers, and so they are curious if you would spend a brief sojourn on Mars. You land your ship near
      5the rover.
      6
      7When you reach the rover, you discover that it's already in the process of rebooting! It's just
      8waiting for someone to enter a BIOS password. The Elf responsible for the rover takes a picture of
      9the password (your puzzle input) and sends it to you via the Digital Sending Network.
     10
     11Unfortunately, images sent via the Digital Sending Network aren't encoded with any normal encoding;
     12instead, they're encoded in a special Space Image Format.  None of the Elves seem to remember why
     13this is the case. They send you the instructions to decode it.
     14
     15Images are sent as a series of digits that each represent the color of a single pixel.  The digits
     16fill each row of the image left-to-right, then move downward to the next row, filling rows
     17top-to-bottom until every pixel of the image is filled.
     18
     19Each image actually consists of a series of identically-sized layers that are filled in this way.
     20So, the first digit corresponds to the top-left pixel of the first layer, the second digit
     21corresponds to the pixel to the right of that on the same layer, and so on until the last digit,
     22which corresponds to the bottom-right pixel of the last layer.
     23
     24For example, given an image 3 pixels wide and 2 pixels tall, the image data 123456789012 corresponds
     25to the following image layers:
     26
     27Layer 1: 123
     28         456
     29
     30Layer 2: 789
     31         012
     32
     33The image you received is 25 pixels wide and 6 pixels tall.
     34
     35To make sure the image wasn't corrupted during transmission, the Elves would like you to find the
     36layer that contains the fewest 0 digits.  On that layer, what is the number of 1 digits multiplied
     37by the number of 2 digits?
     38
     39