aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--2024/src/day20.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/2024/src/day20.cpp b/2024/src/day20.cpp
index 42a2fba..3e79f33 100644
--- a/2024/src/day20.cpp
+++ b/2024/src/day20.cpp
@@ -100,9 +100,34 @@ part1(const tuple<pos_type, pos_type, set<pos_type>>& data)
100 cout << count << endl; 100 cout << count << endl;
101} 101}
102 102
103void
104part2(const tuple<pos_type, pos_type, set<pos_type>>& data)
105{
106 auto path = bfs(data);
107
108 long count = 0;
109 for ( const auto& [pos, dist]: path ) {
110 auto [x, y] = pos;
111
112 for ( size_t r = 2; r != 21; ++r ) {
113 for ( size_t dx = 0; dx != r + 1; ++dx ) {
114 size_t dy = r - dx;
115
116 for ( const auto& new_pos: set<pos_type>{ { x + dx, y + dy }, { x - dx, y + dy }, { x + dx, y - dy }, { x - dx, y - dy } } ) {
117 if ( path.contains(new_pos) && dist < path.at(new_pos) && path.at(new_pos) - dist >= 100 + long(r) ) {
118 ++count;
119 }
120 }
121 }
122 }
123 }
124 cout << count << endl;
125}
126
103int 127int
104main() 128main()
105{ 129{
106 auto data = read_file("data/day20.txt"); 130 auto data = read_file("data/day20.txt");
107 part1(data); 131 part1(data);
132 part2(data);
108} 133}