aboutsummaryrefslogtreecommitdiff
path: root/src/day10.cpp
diff options
context:
space:
mode:
authorThomas Schmucker <ts@its1.de>2024-01-02 20:23:16 +0100
committerThomas Schmucker <ts@its1.de>2024-01-02 20:23:16 +0100
commit1c2555b3574b9498347b8254ec5be90d9e0015f8 (patch)
treef43a5e8dc523af49cdd5a2c7389a3977b0da9c88 /src/day10.cpp
parente95d22d3927549caa5c259a59aedaa67d3b636ca (diff)
downloadadvent-of-code-1c2555b3574b9498347b8254ec5be90d9e0015f8.tar.gz
advent-of-code-1c2555b3574b9498347b8254ec5be90d9e0015f8.tar.bz2
advent-of-code-1c2555b3574b9498347b8254ec5be90d9e0015f8.zip
clean up
Diffstat (limited to 'src/day10.cpp')
-rw-r--r--src/day10.cpp19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/day10.cpp b/src/day10.cpp
index 5591290..264e111 100644
--- a/src/day10.cpp
+++ b/src/day10.cpp
@@ -38,8 +38,7 @@ find_start_pos(const puzzle_t& puzzle)
38bool 38bool
39predict_direction(const puzzle_t& puzzle, pos_t& current, char& direction) 39predict_direction(const puzzle_t& puzzle, pos_t& current, char& direction)
40{ 40{
41 auto x = get<0>(current); // NOLINT 41 auto [x, y] = current;
42 auto y = get<1>(current); // NOLINT
43 42
44 if ( direction == 'S' ) { 43 if ( direction == 'S' ) {
45 ++y; 44 ++y;
@@ -115,10 +114,8 @@ predict_direction(const puzzle_t& puzzle, pos_t& current, char& direction)
115}; 114};
116 115
117void 116void
118part1() 117part1(const puzzle_t& puzzle)
119{ 118{
120 const auto puzzle = read_file("data/day10.txt");
121
122 const auto start_pos = find_start_pos(puzzle); 119 const auto start_pos = find_start_pos(puzzle);
123 120
124 auto max_steps = 0; 121 auto max_steps = 0;
@@ -163,10 +160,8 @@ flood_fill(puzzle_t& puzzle, size_t x, size_t y)
163}; 160};
164 161
165void 162void
166part2() 163part2(const puzzle_t& puzzle_original)
167{ 164{
168 const auto puzzle_original = read_file("data/day10.txt");
169
170 puzzle_t puzzle{ puzzle_original.size(), string(puzzle_original[0].size(), ' ') }; 165 puzzle_t puzzle{ puzzle_original.size(), string(puzzle_original[0].size(), ' ') };
171 166
172 const auto start_pos = find_start_pos(puzzle_original); 167 const auto start_pos = find_start_pos(puzzle_original);
@@ -176,8 +171,7 @@ part2()
176 auto current_pos = start_pos; 171 auto current_pos = start_pos;
177 172
178 for ( ;; ) { 173 for ( ;; ) {
179 auto x = get<0>(current_pos); // NOLINT 174 auto [x, y] = current_pos;
180 auto y = get<1>(current_pos); // NOLINT
181 175
182 puzzle[y][x] = puzzle_original[y][x]; 176 puzzle[y][x] = puzzle_original[y][x];
183 177
@@ -216,6 +210,7 @@ part2()
216int 210int
217main() 211main()
218{ 212{
219 part1(); 213 const auto puzzle = read_file("data/day10.txt");
220 part2(); 214 part1(puzzle);
215 part2(puzzle);
221} 216}