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

View file

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