Created
January 5, 2022 16:46
-
-
Save neofight78/a9073a324e4f163f08c5dd1ea6813cfc to your computer and use it in GitHub Desktop.
Advent of Code 2020 - Day 1: Report Repair
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn part_1(values: &HashSet<i64>) -> i64 { | |
values | |
.iter() | |
.find_map(|&v| { | |
if values.contains(&(2020 - v)) { | |
Some(v * (2020 - v)) | |
} else { | |
None | |
} | |
}) | |
.unwrap() | |
} | |
fn part_2(values: &HashSet<i64>) -> i64 { | |
values | |
.iter() | |
.find_map(|&v| { | |
values.iter().find_map(|&u| { | |
if values.contains(&(2020 - (v + u))) { | |
Some(v * u * (2020 - v - u)) | |
} else { | |
None | |
} | |
}) | |
}) | |
.unwrap() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment