mirror of
https://github.com/chylex/Advent-of-Code.git
synced 2025-05-25 00:34:06 +02:00
Add 2020 - Day 1 - Part 2
This commit is contained in:
parent
065aa6ad45
commit
ef3703949e
@ -6,6 +6,13 @@ mod utils;
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
let lines = utils::parse_input_lines::<u32>()?;
|
||||
|
||||
part1(&lines);
|
||||
part2(&lines);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn part1(lines: &Vec<u32>) {
|
||||
'outer: for i in 0..lines.len() {
|
||||
let value1 = lines.get(i).unwrap();
|
||||
|
||||
@ -14,10 +21,27 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
|
||||
if value1 + value2 == 2020 {
|
||||
println!("Result: {} x {} = {}", value1, value2, value1 * value2);
|
||||
break 'outer
|
||||
break 'outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn part2(lines: &Vec<u32>) {
|
||||
'outer: for i in 0..lines.len() {
|
||||
let value1 = lines.get(i).unwrap();
|
||||
|
||||
for j in (i + 1)..lines.len() {
|
||||
let value2 = lines.get(j).unwrap();
|
||||
|
||||
for k in (j + 1)..lines.len() {
|
||||
let value3 = lines.get(k).unwrap();
|
||||
|
||||
if value1 + value2 + value3 == 2020 {
|
||||
println!("Result: {} x {} x {} = {}", value1, value2, value3, value1 * value2 * value3);
|
||||
break 'outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user