~xenrox/aoc2020

f10f5d05d2cbb744cf9f058b7c8d4c06da91b306 — Thorben Günther 3 years ago ddac8e1
Solve day 1 part 2
1 files changed, 18 insertions(+), 1 deletions(-)

M src/days/day01.rs
M src/days/day01.rs => src/days/day01.rs +18 -1
@@ 11,8 11,25 @@ fn calc_solution1(input: &Vec<i32>) -> i32 {
    panic!("No solution");
}

fn calc_solution2(input: &Vec<i32>) -> i32 {
    for i in 0..input.len() {
        for j in (i + 1)..input.len() {
            for k in (j + 1)..input.len() {
                if (input[i] + input[j] + input[k]) == 2020 {
                    return input[i] * input[j] * input[k];
                }
            }
        }
    }
    panic!("No solution");
}

pub fn get_solution() {
    let contents = fs::read_to_string("data/day01.dat").expect("Could not read data");
    let input: Vec<i32> = contents.lines().flat_map(str::parse).collect();
    println!("Day 1, part 1: {}", calc_solution1(&input));
    println!(
        "Day 1, part 1: {}, part 2: {}",
        calc_solution1(&input),
        calc_solution2(&input)
    );
}