From 0665e109af61cfa41cb92604daa96433baeb65bb Mon Sep 17 00:00:00 2001 From: Keenan Tims Date: Wed, 6 Dec 2023 11:07:40 -0800 Subject: [PATCH] day5: performance: don't iterate to position just do arithemtic --- 5/src/main.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/5/src/main.rs b/5/src/main.rs index ec29177..977b59b 100644 --- a/5/src/main.rs +++ b/5/src/main.rs @@ -163,10 +163,7 @@ impl From<&str> for AlmanacMapping { impl AlmanacMapping { fn lookup(&self, key: u64) -> Option { if self.source_range.contains(&key) { - match self.source_range.clone().position(|x| x == key) { - Some(i) => self.dest_range.clone().nth(i), - None => None, - } + Some(self.dest_range.start + (key - self.source_range.start)) } else { None }