diff options
| author | Thomas Schmucker <ts@its1.de> | 2024-12-20 17:13:14 +0100 |
|---|---|---|
| committer | Thomas Schmucker <ts@its1.de> | 2024-12-20 17:13:14 +0100 |
| commit | 1a4db2303352c067d22fa9aac84921759e003192 (patch) | |
| tree | f3f233b074ff0cdb945045cde144fde055cd1dbd /2024 | |
| parent | 54e6dca438215f499637247f818dbeefafeded80 (diff) | |
| download | advent-of-code-1a4db2303352c067d22fa9aac84921759e003192.tar.gz advent-of-code-1a4db2303352c067d22fa9aac84921759e003192.tar.bz2 advent-of-code-1a4db2303352c067d22fa9aac84921759e003192.zip | |
aoc 2024, day 20, part 2
Diffstat (limited to '2024')
| -rw-r--r-- | 2024/src/day20.cpp | 25 |
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 | ||
| 103 | void | ||
| 104 | part2(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 | |||
| 103 | int | 127 | int |
| 104 | main() | 128 | main() |
| 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 | } |
