Skip to content

Commit

Permalink
Remove big lut
Browse files Browse the repository at this point in the history
  • Loading branch information
EbbDrop committed Dec 8, 2024
1 parent af3ff20 commit 99963cf
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions src/day8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,30 @@ pub fn part1(s: &str) -> u32 {
unsafe { part1_inner(s) }
}

const SHIFT_LUT: [u64; (SIZE * SIZE * 2) as usize] = {
let mut lut = [0; (SIZE * SIZE * 2) as usize];
// const SHIFT_LUT: [u64; (SIZE * SIZE * 2) as usize] = {
// let mut lut = [0; (SIZE * SIZE * 2) as usize];

let mut x = 0;
while x < SIZE {
let mut diff_x = -SIZE + 1;
// let mut x = 0;
// while x < SIZE {
// let mut diff_x = -SIZE + 1;

let field = 1 << x;
// let field = 1 << x;

while diff_x < SIZE {
lut[(x * SIZE * 2 + diff_x + SIZE - 1) as usize] = if diff_x.is_positive() {
field << diff_x
} else {
field >> -diff_x
};
// while diff_x < SIZE {
// lut[(x * SIZE * 2 + diff_x + SIZE - 1) as usize] = if diff_x.is_positive() {
// field << diff_x
// } else {
// field >> -diff_x
// };

diff_x += 1;
}
// diff_x += 1;
// }

x += 1;
}
// x += 1;
// }

lut
};
// lut
// };

unsafe fn part1_inner(s: &str) -> u32 {
#[cfg(not(test))]
Expand Down Expand Up @@ -79,15 +79,21 @@ unsafe fn part1_inner(s: &str) -> u32 {
if *mast_y >= diff_y {
let node_y = mast_y - diff_y;

*antinodes.get_unchecked_mut(node_y as usize) |=
SHIFT_LUT[(mast_x * SIZE * 2 + diff_x + SIZE - 1) as usize];
*antinodes.get_unchecked_mut(node_y as usize) |= if diff_x.is_positive() {
1 << mast_x << diff_x
} else {
1 << mast_x >> -diff_x
};
}

if new_y + diff_y < SIZE {
let node_y = new_y + diff_y;

*antinodes.get_unchecked_mut(node_y as usize) |=
SHIFT_LUT[(new_x * SIZE * 2 - diff_x + SIZE - 1) as usize];
*antinodes.get_unchecked_mut(node_y as usize) |= if diff_x.is_positive() {
1 << new_x << diff_x
} else {
1 << new_x >> -diff_x
};
}
}

Expand Down

0 comments on commit 99963cf

Please sign in to comment.