Rust: small optimization for day9 part1
This commit is contained in:
parent
e13d0225bc
commit
a84c3e49f5
|
@ -381,19 +381,16 @@ mod day09 {
|
|||
use std::time::{Duration, Instant};
|
||||
|
||||
fn part1(numbers: &[usize]) -> usize {
|
||||
for (i, &n) in numbers.iter().enumerate().skip(COUNT) {
|
||||
let mut found = false;
|
||||
'outer: for (i, &n) in numbers.iter().enumerate().skip(COUNT) {
|
||||
for x in i - COUNT..i {
|
||||
for y in x + 1..i {
|
||||
if numbers[x] + numbers[y] == n {
|
||||
found = true;
|
||||
continue 'outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
return n;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
panic!();
|
||||
|
@ -416,7 +413,8 @@ mod day09 {
|
|||
}
|
||||
}
|
||||
|
||||
numbers[lower..upper].iter().min().unwrap() + numbers[lower..upper].iter().max().unwrap()
|
||||
let slice = &numbers[lower..upper];
|
||||
slice.iter().min().unwrap() + slice.iter().max().unwrap()
|
||||
}
|
||||
|
||||
const COUNT: usize = 25;
|
||||
|
|
Loading…
Reference in New Issue