@@ -33,7 +33,7 @@ unsafe fn part1_inner(s: &str) -> u32 {
3333 let mut masts: [ ArrayVec < [ ( i16 , i16 , u64 ) ; 3 ] > ; FREQ_RANGE ] =
3434 [ ArrayVec :: from_array_empty ( [ ( 0 , 0 , 0 ) ; 3 ] ) ; FREQ_RANGE ] ;
3535
36- let mut antinodes = [ 0u64 ; SIZE as usize ] ;
36+ let mut antinodes = [ 0u64 ; SIZE as usize * 3 ] ;
3737
3838 for i in unsafe { OneInv :: new_unchecked ( b'.' ) . iter ( s) } {
3939 if s[ i] == b'\n' {
@@ -53,31 +53,25 @@ unsafe fn part1_inner(s: &str) -> u32 {
5353 let diff_x = mast_x - new_x;
5454 let diff_y = new_y - mast_y;
5555
56- if * mast_y >= diff_y {
57- let node_y = mast_y - diff_y;
58-
59- * antinodes. get_unchecked_mut ( node_y as usize ) |= if diff_x. is_positive ( ) {
60- mast_field << diff_x
61- } else {
62- mast_field >> -diff_x
63- } ;
64- }
65-
66- if new_y + diff_y < SIZE {
67- let node_y = new_y + diff_y;
68-
69- * antinodes. get_unchecked_mut ( node_y as usize ) |= if diff_x. is_positive ( ) {
70- new_field >> diff_x
71- } else {
72- new_field << -diff_x
73- } ;
74- }
56+ let node_y = mast_y - diff_y;
57+ * antinodes. get_unchecked_mut ( ( node_y + SIZE ) as usize ) |= if diff_x. is_positive ( ) {
58+ mast_field << diff_x
59+ } else {
60+ mast_field >> -diff_x
61+ } ;
62+
63+ let node_y = new_y + diff_y;
64+ * antinodes. get_unchecked_mut ( ( node_y + SIZE ) as usize ) |= if diff_x. is_positive ( ) {
65+ new_field >> diff_x
66+ } else {
67+ new_field << -diff_x
68+ } ;
7569 }
7670
7771 masts[ f as usize ] . try_push ( ( new_y, new_x, new_field) ) ;
7872 }
7973
80- antinodes
74+ antinodes[ SIZE as usize .. ( SIZE * 2 ) as usize ]
8175 . iter ( )
8276 . map ( |field| ( field & FIELD_SIZE ) . count_ones ( ) )
8377 . sum ( )
0 commit comments