Skip to content

Commit 57edfa1

Browse files
committed
Find all cheat paths in demo properly
1 parent c402a9c commit 57edfa1

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

day20/src/day20.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,10 @@ impl Racetrack {
8181

8282
while let Some(node) = queue.pop() {
8383
if node.pos == end {
84-
// dbg!(paths.len(), node.picos);
85-
paths.push(node);
8684
if !condition(node) {
8785
break;
8886
}
87+
paths.push(node);
8988
}
9089

9190
for dy in -1..=1 {
@@ -144,13 +143,15 @@ fn main() {
144143
let start = track.locate('S').unwrap();
145144
let end = track.locate('E').unwrap();
146145

147-
let shortest_path = track.find_paths(start, end, CheatPolicy::Forbidden, |_| false)[0];
146+
let shortest_path = track.find_paths(start, end, CheatPolicy::Forbidden, |_| true)[0];
148147
let base_picos = shortest_path.picos;
149148

150-
let paths = track.find_paths(start, end, CheatPolicy::Allowed, |_| true);
151-
// let part1 = paths.len();
149+
let cheat_paths = track.find_paths(start, end, CheatPolicy::Allowed, |n| n.picos < base_picos);
150+
let part1 = cheat_paths.len();
152151

153-
for p in paths.iter().take(20).map(|n| (base_picos - n.picos, n.cheat)) {
152+
for p in cheat_paths.iter().map(|n| (base_picos - n.picos, n.cheat)) {
154153
println!("{p:?}");
155154
}
155+
156+
println!("Part 1: {part1}");
156157
}

0 commit comments

Comments
 (0)