diff --git a/src/day8.rs b/src/day8.rs index a74fd81..87363f7 100644 --- a/src/day8.rs +++ b/src/day8.rs @@ -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))] @@ -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 + }; } }