Skip to content

Instantly share code, notes, and snippets.

@neofight78
Created January 5, 2022 16:46
Show Gist options
  • Save neofight78/a9073a324e4f163f08c5dd1ea6813cfc to your computer and use it in GitHub Desktop.
Save neofight78/a9073a324e4f163f08c5dd1ea6813cfc to your computer and use it in GitHub Desktop.
Advent of Code 2020 - Day 1: Report Repair
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