Skip to content

Commit 38f1ebb

Browse files
committed
Revert "Have unused space in field vec"
This reverts commit 12f85f6.
1 parent 12f85f6 commit 38f1ebb

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

src/day8.rs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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 * 3];
36+
let mut antinodes = [0u64; SIZE as usize];
3737

3838
for i in unsafe { OneInv::new_unchecked(b'.').iter(s) } {
3939
if s[i] == b'\n' {
@@ -53,25 +53,31 @@ 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-
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-
};
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+
}
6975
}
7076

7177
masts[f as usize].try_push((new_y, new_x, new_field));
7278
}
7379

74-
antinodes[SIZE as usize..(SIZE * 2) as usize]
80+
antinodes
7581
.iter()
7682
.map(|field| (field & FIELD_SIZE).count_ones())
7783
.sum()

0 commit comments

Comments
 (0)