Added Day 1 Part 2 and the smaller test input as well
This commit is contained in:
parent
6058f7753d
commit
743260c752
6
small.input
Normal file
6
small.input
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
1721
|
||||||
|
979
|
||||||
|
366
|
||||||
|
299
|
||||||
|
675
|
||||||
|
1456
|
16
src/main.rs
16
src/main.rs
|
@ -9,12 +9,20 @@ fn main() {
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.filter(|x| !x.is_empty())
|
.filter(|x| !x.is_empty())
|
||||||
.map(|x| x.parse::<u64>().unwrap())
|
.map(|x| x.parse::<u64>().unwrap())
|
||||||
|
.filter(|&x| x <= 2020)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
for &num in numbers.iter() {
|
'outer: for (i, &num1) in numbers.iter().enumerate() {
|
||||||
if numbers.contains(&(2020 - num)) {
|
let diff = 2020 - num1;
|
||||||
println!("{}", num * (2020 - num));
|
|
||||||
break;
|
for (j, &num2) in numbers.iter().enumerate() {
|
||||||
|
if i == j {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if numbers.contains(&(diff - num2)) {
|
||||||
|
println!("{}", num1 * num2 * (diff - num2));
|
||||||
|
break 'outer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user