rust(day09): Optimize further

This commit is contained in:
Sijmen 2020-12-16 01:50:40 +01:00
parent a84c3e49f5
commit ff1d3a67e5
Signed by: vijfhoek
GPG Key ID: DAF7821E067D9C48
1 changed files with 7 additions and 3 deletions

View File

@ -381,16 +381,20 @@ mod day09 {
use std::time::{Duration, Instant};
fn part1(numbers: &[usize]) -> usize {
'outer: for (i, &n) in numbers.iter().enumerate().skip(COUNT) {
'outer: for i in COUNT..numbers.len() {
for x in i - COUNT..i {
if numbers[x] > numbers[i] {
continue;
}
for y in x + 1..i {
if numbers[x] + numbers[y] == n {
if numbers[x] + numbers[y] == numbers[i] {
continue 'outer;
}
}
}
return n;
return numbers[i];
}
panic!();