1
0

Added Day 1 Part 2 and the smaller test input as well

This commit is contained in:
Ishan Jain 2020-12-02 08:24:05 +05:30
parent 6058f7753d
commit 743260c752
No known key found for this signature in database
GPG Key ID: F261A0E73038D89D
2 changed files with 18 additions and 4 deletions

6
small.input Normal file
View File

@ -0,0 +1,6 @@
1721
979
366
299
675
1456

View File

@ -9,12 +9,20 @@ fn main() {
.split('\n')
.filter(|x| !x.is_empty())
.map(|x| x.parse::<u64>().unwrap())
.filter(|&x| x <= 2020)
.collect();
for &num in numbers.iter() {
if numbers.contains(&(2020 - num)) {
println!("{}", num * (2020 - num));
break;
'outer: for (i, &num1) in numbers.iter().enumerate() {
let diff = 2020 - num1;
for (j, &num2) in numbers.iter().enumerate() {
if i == j {
continue;
}
if numbers.contains(&(diff - num2)) {
println!("{}", num1 * num2 * (diff - num2));
break 'outer;
}
}
}
}