AoC 2019 D8: Space Image Format

C++ | Problem statement | Source code | Tags: Image processingManual inspection

← Previous Back to AoC Index Next →

Part 1

I don't even need to build an actual 3D array representing the image. I know that width = 25 and height = 6, so I have layer_size = width * height and num_layers = input.size() / layer_size. Then I can iterate over layer and i and index into input[layer * layer_size + i].

Part 2

I built the image as a vector<int>, where each element is 2 (transparent) initially. Then I iterate over each layer and update the pixel in the image if it is still transparent. Finally I print it out by iterating over 0..height and 0..width. Originally I printed them backwards (0 as # since it's "black"), but then I realized it's easier to read with 1 as # since the console background is black.

I take a second to admire the ASCII art:

#     ##  #   ##  # ###
# # # # ## # # #
# # # # #### ###
# # ## # # # # #
# # # # # # # #
#### ### # # # ###

← Previous Back to AoC Index Next →