Skip to content

Commit

Permalink
?
Browse files Browse the repository at this point in the history
  • Loading branch information
Icerath committed Dec 16, 2024
1 parent 4453464 commit 0c4de39
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/day15.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,14 @@ unsafe fn part2_inner(input: &[u8]) -> usize {
let mut i = 0;
for _ in 0..20 {
for _ in 0..1000 {
let dir = *P2_DIRECTION_LUT.get_unchecked(directions[i] as usize);
let dir = match directions[i] {
b'^' => -100,
b'>' => 1,
b'v' => 100,
b'<' => -1,
_ => unreachable_unchecked(),
};
// let dir = *P2_DIRECTION_LUT.get_unchecked(directions[i] as usize);
i += 1;
let next_pos = pos.wrapping_add_signed(dir);
if !can_push_box(&grid, next_pos, dir) {
Expand Down Expand Up @@ -177,17 +184,12 @@ unsafe fn push_box_vertical(grid: &mut [u8; 100 * 50], pos: usize, dir: isize) {
}
}

macro_rules! direction_lut {
($vert: literal) => {{
let mut lut = [0; LARGEST_DIRECTION];
lut[b'^' as usize] = -$vert;
lut[b'>' as usize] = 1;
lut[b'v' as usize] = $vert;
lut[b'<' as usize] = -1;
lut
}};
}

const LARGEST_DIRECTION: usize = b'v' as usize + 1;
static P1_DIRECTION_LUT: [isize; LARGEST_DIRECTION] = direction_lut!(51);
static P2_DIRECTION_LUT: [isize; LARGEST_DIRECTION] = direction_lut!(100);
static P1_DIRECTION_LUT: [isize; LARGEST_DIRECTION] = {
let mut lut = [0; LARGEST_DIRECTION];
lut[b'^' as usize] = -51;
lut[b'>' as usize] = 1;
lut[b'v' as usize] = 51;
lut[b'<' as usize] = -1;
lut
};

0 comments on commit 0c4de39

Please sign in to comment.