From ff1d3a67e50dbff76dd06aba05b88d0aa8a8caa5 Mon Sep 17 00:00:00 2001 From: Sijmen Schoon Date: Wed, 16 Dec 2020 01:50:40 +0100 Subject: [PATCH] rust(day09): Optimize further --- rust/src/main.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/rust/src/main.rs b/rust/src/main.rs index 76276e2..d67e7c0 100644 --- a/rust/src/main.rs +++ b/rust/src/main.rs @@ -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!();