Improved 2022 - Day 8 by stopping early if the highest possible score can not exceed the current highest score
This commit is contained in:
parent
225537f364
commit
b084f178ee
|
@ -125,6 +125,11 @@ impl aoc::Solver for Day {
|
|||
let mut distance_up = 0;
|
||||
let mut distance_down = 0;
|
||||
|
||||
// Bail early if the tree can not exceed the current highest
|
||||
if x * (input[y].len()-x-1) * y * (input.len()-y-1) < score_highest {
|
||||
continue;
|
||||
}
|
||||
|
||||
for c in (0..x).rev() {
|
||||
distance_left += 1;
|
||||
if input[y][c] >= height {
|
||||
|
@ -132,6 +137,10 @@ impl aoc::Solver for Day {
|
|||
}
|
||||
}
|
||||
|
||||
if distance_left * (input[y].len()-x-1) * y * (input.len()-y-1) < score_highest {
|
||||
continue;
|
||||
}
|
||||
|
||||
for c in x+1..input[y].len() {
|
||||
distance_right += 1;
|
||||
if input[y][c] >= height {
|
||||
|
@ -139,6 +148,10 @@ impl aoc::Solver for Day {
|
|||
}
|
||||
}
|
||||
|
||||
if distance_left * distance_right * y * (input.len()-y-1) < score_highest {
|
||||
continue;
|
||||
}
|
||||
|
||||
for r in (0..y).rev() {
|
||||
distance_up += 1;
|
||||
if input[r][x] >= height {
|
||||
|
@ -146,6 +159,10 @@ impl aoc::Solver for Day {
|
|||
}
|
||||
}
|
||||
|
||||
if distance_left * distance_right * distance_up * (input.len()-y-1) < score_highest {
|
||||
continue;
|
||||
}
|
||||
|
||||
for r in y+1..input[y].len() {
|
||||
distance_down += 1;
|
||||
if input[r][x] >= height {
|
||||
|
|
Loading…
Reference in New Issue
Block a user