Skip to content

Commit 1b5a30a

Browse files
committed
Early exit in part 1
1 parent 9583295 commit 1b5a30a

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/day10.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ unsafe fn part1_inner(s: &str) -> u32 {
4343
let mut current = &mut [0u64; MAX_SIZE + 2];
4444

4545
let mut sum = 0;
46-
for (x, y) in &zeros[..zeros_i] {
46+
'outer: for (x, y) in &zeros[..zeros_i] {
4747
current[*y + 1] |= 1 << *x;
4848
for layer in 0..9 {
4949
// for yp1 in 1..size + 1 {
@@ -59,16 +59,21 @@ unsafe fn part1_inner(s: &str) -> u32 {
5959
// }
6060
// println!("");
6161

62+
let mut any = 0;
6263
for yp1 in 1..size + 1 {
6364
let to_left = (current[yp1] << 1) & maps[layer][yp1];
6465
let to_right = (current[yp1] >> 1) & maps[layer][yp1];
6566
let to_down = current[yp1 - 1] & maps[layer][yp1];
6667
let to_up = current[yp1 + 1] & maps[layer][yp1];
6768

68-
let to_left_and_right = to_left | to_right;
69-
let to_left_down_and_right = to_left_and_right | to_down;
70-
71-
next[yp1] = to_left_down_and_right | to_up;
69+
let total = to_left | to_right | to_down | to_up;
70+
any |= total;
71+
next[yp1] = total;
72+
}
73+
if any == 0 {
74+
next.fill(0);
75+
current.fill(0);
76+
continue 'outer;
7277
}
7378

7479
std::mem::swap(&mut current, &mut next);

0 commit comments

Comments
 (0)