Skip to content

Commit a83bbb4

Browse files
committed
Use even diffrent boundry condition
1 parent d66fd0d commit a83bbb4

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/day8.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ const SIZE: i32 = 50;
88
#[cfg(test)]
99
const SIZE: i32 = 12;
1010

11-
const SIZE1: i32 = SIZE + 1;
12-
1311
/// Has the `SIZE` lsb set
1412
const FIELD_SIZE: u64 = 2u64.pow(SIZE as u32) - 1;
1513

@@ -155,11 +153,11 @@ unsafe fn part2_inner(s: &str) -> u32 {
155153
let diff_x_o = mast_x - new_x;
156154
let diff_y_o = new_y - mast_y;
157155

158-
for k in 0.. {
156+
for k in 0..(SIZE / diff_x_o.abs()) {
159157
let diff_x = diff_x_o * k;
160158
let diff_y = diff_y_o * k;
161159

162-
if *mast_y >= diff_y && diff_x.abs() < 50 {
160+
if *mast_y >= diff_y {
163161
let node_y = mast_y - diff_y;
164162

165163
*antinodes.get_unchecked_mut(node_y as usize) |= if diff_x.is_positive() {
@@ -172,11 +170,11 @@ unsafe fn part2_inner(s: &str) -> u32 {
172170
}
173171
}
174172

175-
for k in 0.. {
173+
for k in 0..(SIZE / diff_x_o.abs()) {
176174
let diff_x = diff_x_o * k;
177175
let diff_y = diff_y_o * k;
178176

179-
if new_y + diff_y < SIZE && diff_x.abs() < 50 {
177+
if new_y + diff_y < SIZE {
180178
let node_y = new_y + diff_y;
181179

182180
*antinodes.get_unchecked_mut(node_y as usize) |= if diff_x.is_positive() {

0 commit comments

Comments
 (0)