Mercurial > hg > aoc
comparison 2017/day21/problem @ 34:049fb8e56025
Add problem statements and inputs
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Tue, 09 Jan 2018 21:51:44 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
33:bc652fa0a645 | 34:049fb8e56025 |
---|---|
1 --- Day 21: Fractal Art --- | |
2 | |
3 You find a program trying to generate some art. It uses a strange | |
4 process that involves repeatedly enhancing the detail of an image | |
5 through a set of rules. | |
6 | |
7 The image consists of a two-dimensional square grid of pixels that are | |
8 either on (#) or off (.). The program always begins with this pattern: | |
9 | |
10 .#. | |
11 ..# | |
12 ### | |
13 | |
14 Because the pattern is both 3 pixels wide and 3 pixels tall, it is | |
15 said to have a size of 3. | |
16 | |
17 Then, the program repeats the following process: | |
18 | |
19 If the size is evenly divisible by 2, break the pixels up into 2x2 | |
20 squares, and convert each 2x2 square into a 3x3 square by | |
21 following the corresponding enhancement rule. | |
22 | |
23 Otherwise, the size is evenly divisible by 3; break the pixels up | |
24 into 3x3 squares, and convert each 3x3 square into a 4x4 square by | |
25 following the corresponding enhancement rule. | |
26 | |
27 | |
28 Because each square of pixels is replaced by a larger one, the image | |
29 gains pixels and so its size increases. | |
30 | |
31 The artist's book of enhancement rules is nearby (your puzzle input); | |
32 however, it seems to be missing rules. The artist explains that | |
33 sometimes, one must rotate or flip the input pattern to find a match. | |
34 (Never rotate or flip the output pattern, though.) Each pattern is | |
35 written concisely: rows are listed as single units, ordered top-down, | |
36 and separated by slashes. For example, the following rules correspond | |
37 to the adjacent patterns: | |
38 | |
39 ../.# = .. | |
40 .# | |
41 | |
42 .#. | |
43 .#./..#/### = ..# | |
44 ### | |
45 | |
46 #..# | |
47 #..#/..../#..#/.##. = .... | |
48 #..# | |
49 .##. | |
50 | |
51 When searching for a rule to use, rotate and flip the pattern as | |
52 necessary. For example, all of the following patterns match the same | |
53 rule: | |
54 | |
55 .#. .#. #.. ### | |
56 ..# #.. #.# ..# | |
57 ### ### ##. .#. | |
58 | |
59 Suppose the book contained the following two rules: | |
60 | |
61 ../.# => ##./#../... | |
62 .#./..#/### => #..#/..../..../#..# | |
63 | |
64 As before, the program begins with this pattern: | |
65 | |
66 .#. | |
67 ..# | |
68 ### | |
69 | |
70 The size of the grid (3) is not divisible by 2, but it is divisible by | |
71 3. It divides evenly into a single square; the square matches the | |
72 second rule, which produces: | |
73 | |
74 #..# | |
75 .... | |
76 .... | |
77 #..# | |
78 | |
79 The size of this enhanced grid (4) is evenly divisible by 2, so that | |
80 rule is used. It divides evenly into four squares: | |
81 | |
82 #.|.# | |
83 ..|.. | |
84 --+-- | |
85 ..|.. | |
86 #.|.# | |
87 | |
88 Each of these squares matches the same rule (../.# => ##./#../...), | |
89 three of which require some flipping and rotation to line up with the | |
90 rule. The output for the rule is the same in all four cases: | |
91 | |
92 ##.|##. | |
93 #..|#.. | |
94 ...|... | |
95 ---+--- | |
96 ##.|##. | |
97 #..|#.. | |
98 ...|... | |
99 | |
100 Finally, the squares are joined into a new grid: | |
101 | |
102 ##.##. | |
103 #..#.. | |
104 ...... | |
105 ##.##. | |
106 #..#.. | |
107 ...... | |
108 | |
109 Thus, after 2 iterations, the grid contains 12 pixels that are on. | |
110 | |
111 How many pixels stay on after 5 iterations? | |
112 | |
113 Your puzzle answer was 176. | |
114 | |
115 --- Part Two --- | |
116 | |
117 How many pixels stay on after 18 iterations? | |
118 | |
119 Your puzzle answer was 2368161. | |
120 | |
121 Both parts of this puzzle are complete! They provide two gold stars: ** |