Skip to content

Commit e31b20b

Browse files
committed
Try crunching part 2
Yeah, this is probably not going to work in reasonable time, but let's try...
1 parent 46993d1 commit e31b20b

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

day20/src/day20.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl PartialOrd for Node {
4646

4747
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
4848
enum CheatPolicy {
49-
Allowed,
49+
Allowed { picos: i32 },
5050
Forbidden,
5151
}
5252

@@ -96,7 +96,7 @@ impl Racetrack {
9696
if self.in_bounds(neigh) {
9797
let is_wall = self[neigh] == '#';
9898

99-
let cheats_allowed = cheat_policy == CheatPolicy::Allowed;
99+
let cheats_allowed = matches!(cheat_policy, CheatPolicy::Allowed { .. });
100100
let can_cheat = cheats_allowed && node.cheat.map_or(true, |c| c.picos_left > 0);
101101
let new_cheat = if let Some(cheat) = node.cheat {
102102
let is_ending = cheat.picos_left == 1;
@@ -105,7 +105,11 @@ impl Racetrack {
105105
}
106106
Some(Cheat { start: cheat.start, end: if is_ending { Some(neigh) } else { cheat.end }, picos_left: (cheat.picos_left - 1).max(0) })
107107
} else if cheats_allowed && is_wall {
108-
Some(Cheat { start: node.pos, end: None, picos_left: 1 })
108+
if let CheatPolicy::Allowed { picos: cheat_picos } = cheat_policy {
109+
Some(Cheat { start: node.pos, end: None, picos_left: cheat_picos })
110+
} else {
111+
unreachable!()
112+
}
109113
} else {
110114
node.cheat
111115
};
@@ -152,8 +156,11 @@ fn main() {
152156
let shortest_path = track.find_paths(start, end, CheatPolicy::Forbidden, |_| true)[0];
153157
let base_picos = shortest_path.picos;
154158

155-
let cheat_paths = track.find_paths(start, end, CheatPolicy::Allowed, |n| n.picos <= base_picos - 100);
156-
let part1 = cheat_paths.len();
159+
// let cheat_paths1 = track.find_paths(start, end, CheatPolicy::Allowed { picos: 2 }, |n| n.picos <= base_picos - 100);
160+
// let part1 = cheat_paths1.len();
161+
// println!("Part 1: {part1}");
157162

158-
println!("Part 1: {part1}");
163+
let cheat_paths2 = track.find_paths(start, end, CheatPolicy::Allowed { picos: 20 }, |n| n.picos <= base_picos - 100);
164+
let part2 = cheat_paths2.len();
165+
println!("Part 2: {part2}");
159166
}

0 commit comments

Comments
 (0)