Rust: small optimization for day9 part1
This commit is contained in:
parent
e13d0225bc
commit
a84c3e49f5
1 changed files with 5 additions and 7 deletions
|
@ -381,20 +381,17 @@ mod day09 {
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
fn part1(numbers: &[usize]) -> usize {
|
fn part1(numbers: &[usize]) -> usize {
|
||||||
for (i, &n) in numbers.iter().enumerate().skip(COUNT) {
|
'outer: for (i, &n) in numbers.iter().enumerate().skip(COUNT) {
|
||||||
let mut found = false;
|
|
||||||
for x in i - COUNT..i {
|
for x in i - COUNT..i {
|
||||||
for y in x + 1..i {
|
for y in x + 1..i {
|
||||||
if numbers[x] + numbers[y] == n {
|
if numbers[x] + numbers[y] == n {
|
||||||
found = true;
|
continue 'outer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !found {
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
panic!();
|
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;
|
const COUNT: usize = 25;
|
||||||
|
|
Loading…
Reference in a new issue