December 07, 2024

Solution for Advent of Code 2017 - Day 21: Fractal Art

Link to the puzzle text

Part 1

In this puzzle, we have a 2D grid and list of transformation rules. We are asked to run multiple rounds of tranformations. For each round, the grid is divided into 2x2 or 3x3 patches and replaced with a larger patch according to the given transformation rules. When checking the patches against the rules, the patches can be flipped and rotated before applying. Finally we should return the number of '#' characters in the final grid after 5 rounds.

For the rules, we built up a dictionary of all replacements. While reading in the rules, we also add the flipped and rotated versions as input to the dictionary. This simplifies the checking later on. For the replacements, we first create a new grid and fill it line by line with the replaced versions after checking the previously created rules dictionary. Since the code for replacing a 2x2 and a 3x3 patch are basically the same, we introduced a pattern_size variable instead of writing similar code twice.

Part 2

In part 2, we should run the rules for 18 instead of 5 rounds.

For this, no further implementation was necessary except changing the number of rounds.

Link to my solutions

No comments:

Post a Comment