aboutsummaryrefslogtreecommitdiff
path: root/src/day21.cpp
diff options
context:
space:
mode:
authorThomas Schmucker <ts@its1.de>2024-01-03 11:35:34 +0100
committerThomas Schmucker <ts@its1.de>2024-01-03 11:35:34 +0100
commitb11265b0cccd1f4c236327529c1e4623931bd2f0 (patch)
tree5922f45db832129156ac518c02083f185832e362 /src/day21.cpp
parent791ab71d2bb76b1d3ab7074f4c86e91b013349aa (diff)
downloadadvent-of-code-b11265b0cccd1f4c236327529c1e4623931bd2f0.tar.gz
advent-of-code-b11265b0cccd1f4c236327529c1e4623931bd2f0.tar.bz2
advent-of-code-b11265b0cccd1f4c236327529c1e4623931bd2f0.zip
naming
Diffstat (limited to 'src/day21.cpp')
-rw-r--r--src/day21.cpp45
1 files changed, 23 insertions, 22 deletions
diff --git a/src/day21.cpp b/src/day21.cpp
index 740c3ae..c633155 100644
--- a/src/day21.cpp
+++ b/src/day21.cpp
@@ -108,34 +108,35 @@ part2(const vector<string>& lines)
108 const size_t steps = 26501365; 108 const size_t steps = 26501365;
109 const auto grid_width = steps / size - 1; 109 const auto grid_width = steps / size - 1;
110 110
111 const auto odd = pow2(grid_width / 2 * 2 + 1); 111 const auto num_odd_tiles = pow2(grid_width / 2 * 2 + 1);
112 const auto even = pow2((grid_width + 1) / 2 * 2); 112 const auto num_even_tiles = pow2((grid_width + 1) / 2 * 2);
113 const auto num_odd_points = count(lines, start, size * 2 + 1);
114 const auto num_even_points = count(lines, start, size * 2);
113 115
114 const auto odd_points = count(lines, start, size * 2 + 1); 116 auto sum = num_odd_tiles * num_odd_points + num_even_tiles * num_even_points;
115 const auto even_points = count(lines, start, size * 2);
116 117
117 const auto corner_t = count(lines, { size - 1, col }, size - 1); 118 const auto corner_top = count(lines, { size - 1, col }, size - 1);
118 const auto corner_r = count(lines, { row, 0 }, size - 1); 119 const auto corner_right = count(lines, { row, 0 }, size - 1);
119 const auto corner_b = count(lines, { 0, col }, size - 1); 120 const auto corner_bottom = count(lines, { 0, col }, size - 1);
120 const auto corner_l = count(lines, { row, size - 1 }, size - 1); 121 const auto corner_left = count(lines, { row, size - 1 }, size - 1);
121 122
122 const auto small_tr = count(lines, { size - 1, 0 }, size / 2 - 1); 123 sum += corner_top + corner_right + corner_bottom + corner_left;
123 const auto small_tl = count(lines, { size - 1, size - 1 }, size / 2 - 1);
124 const auto small_br = count(lines, { 0, 0 }, size / 2 - 1);
125 const auto small_bl = count(lines, { 0, size - 1 }, size / 2 - 1);
126 124
127 const auto large_tr = count(lines, { size - 1, 0 }, size * 3 / 2 - 1); 125 const auto small_top_right = count(lines, { size - 1, 0 }, size / 2 - 1);
128 const auto large_tl = count(lines, { size - 1, size - 1 }, size * 3 / 2 - 1); 126 const auto small_top_left = count(lines, { size - 1, size - 1 }, size / 2 - 1);
129 const auto large_br = count(lines, { 0, 0 }, size * 3 / 2 - 1); 127 const auto small_bottom_right = count(lines, { 0, 0 }, size / 2 - 1);
130 const auto large_bl = count(lines, { 0, size - 1 }, size * 3 / 2 - 1); 128 const auto small_bottom_left = count(lines, { 0, size - 1 }, size / 2 - 1);
131 129
132 auto total = odd * odd_points; 130 sum += (grid_width + 1) * (small_top_right + small_top_left + small_bottom_right + small_bottom_left);
133 total += even * even_points;
134 total += corner_t + corner_r + corner_b + corner_l;
135 total += (grid_width + 1) * (small_tr + small_tl + small_br + small_bl);
136 total += grid_width * (large_tr + large_tl + large_br + large_bl);
137 131
138 cout << total << endl; 132 const auto large_top_right = count(lines, { size - 1, 0 }, size * 3 / 2 - 1);
133 const auto large_top_left = count(lines, { size - 1, size - 1 }, size * 3 / 2 - 1);
134 const auto large_bottom_right = count(lines, { 0, 0 }, size * 3 / 2 - 1);
135 const auto large_bottom_left = count(lines, { 0, size - 1 }, size * 3 / 2 - 1);
136
137 sum += grid_width * (large_top_right + large_top_left + large_bottom_right + large_bottom_left);
138
139 cout << sum << endl;
139} 140}
140 141
141int 142int