Skip to content

Commit

Permalink
perf(day16): invert condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Samuels committed Dec 16, 2024
1 parent 7ee5ab2 commit d897891
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions src/day16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,30 +286,28 @@ unsafe fn inner_p2<const DIM: usize>(

crate::debug!("Path through {index:?}, {dir:?} with value {value}");

if value >= 1_000 {
if curr_tile[dir.rotate_clockwise() as usize] == value - 1_000 {
stack.push_unchecked(StackEntry {
index,
dir: dir.rotate_clockwise(),
});
}
if curr_tile[dir.rotate_clockwise() as usize].saturating_add(1_000) == value {
stack.push_unchecked(StackEntry {
index,
dir: dir.rotate_clockwise(),
});
}

if curr_tile[dir.rotate_widdershins() as usize] == value - 1_000 {
stack.push_unchecked(StackEntry {
index,
dir: dir.rotate_widdershins(),
});
}
if curr_tile[dir.rotate_widdershins() as usize].saturating_add(1_000) == value {
stack.push_unchecked(StackEntry {
index,
dir: dir.rotate_widdershins(),
});
}

if value >= 1 {
let old_pos = index - dir.into();
if curr_cost[old_pos.y as usize][old_pos.x as usize][dir as usize] == value - 1 {
stack.push_unchecked(StackEntry {
index: old_pos,
dir,
});
}
let old_pos = index - dir.into();
if curr_cost[old_pos.y as usize][old_pos.x as usize][dir as usize].saturating_add(1)
== value
{
stack.push_unchecked(StackEntry {
index: old_pos,
dir,
});
}
}

Expand Down

0 comments on commit d897891

Please sign in to comment.