28 lines
686 B
Rust
28 lines
686 B
Rust
use itertools::Itertools;
|
|
use std::error::Error;
|
|
use std::fs::File;
|
|
use std::io::{self, BufRead};
|
|
use std::vec::Vec;
|
|
|
|
fn main() -> Result<(), Box<dyn Error>> {
|
|
let file = File::open("inputs/day1.txt")?;
|
|
let lines = io::BufReader::new(file).lines();
|
|
|
|
let numbers: Vec<u32> = lines.map(|l| l.unwrap().parse().unwrap()).collect();
|
|
|
|
let count = 3;
|
|
|
|
for combo in numbers.iter().combinations(count) {
|
|
if combo.iter().fold(0u32, |acc, x| acc + **x) == 2020 {
|
|
println!(
|
|
"Combo: {:?} == {}",
|
|
combo,
|
|
combo.iter().fold(1u32, |acc, x| acc * **x)
|
|
);
|
|
break;
|
|
}
|
|
}
|
|
|
|
Ok(())
|
|
}
|