day5: performance: don't iterate to position just do arithemtic

This commit is contained in:
Keenan Tims 2023-12-06 11:07:40 -08:00
parent 6d1174e2db
commit 0665e109af
No known key found for this signature in database
GPG Key ID: B8FDD4AD6B193F06

View File

@ -163,10 +163,7 @@ impl From<&str> for AlmanacMapping {
impl AlmanacMapping {
fn lookup(&self, key: u64) -> Option<u64> {
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
}