Advent of code 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
842 B

use std::fs::File;
use std::io::{prelude::*, BufReader, Error};
pub fn aoc_01_01(filename: &str) -> Result<(), Error> {
let file = File::open(filename).expect("No file");
let br = BufReader::new(file);
let mut v: Vec<i64> = vec![];
for line in br.lines() {
v.push(line?
.trim()
.parse().unwrap());
}
for i in 0..v.len()-2 {
for j in i+1..v.len()-1 {
if v[i] + v[j] == 2020 {
println!("aoc_01_01 result: {}", v[i]*v[j]);
}
}
}
for i in 0..v.len()-3 {
for j in i+1..v.len()-2 {
for k in j+1..v.len()-1 {
if v[i] + v[j] + v[k] == 2020 {
println!("aoc_01_02 result: {}", v[i] * v[j] * v[k]);
}
}
}
}
return Ok(());
}