Skip to content

Commit f1d6d84

Browse files
authored
refactor: Optimise algorithm by removing redundant full levels check
1 parent e232c20 commit f1d6d84

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

src/day02.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,10 @@ pub fn solve_part2(input: &str) -> i32 {
1010
.lines()
1111
.filter(|report| {
1212
let levels = parse_levels(report);
13-
if is_safe(&levels) {
14-
return true;
15-
}
16-
1713
// Check if removing one element results in a safe sequence
1814
(0..levels.len()).any(|i| {
1915
let (left, right) = levels.split_at(i);
20-
is_safe(&[left, &right[1..]].concat()) //always leave out first element from right
16+
is_safe(&[left, &right[1..]].concat())
2117
})
2218
})
2319
.count() as i32

0 commit comments

Comments
 (0)