@@ 0,0 1,60 @@
+use std::fs::File;
+use std::io::prelude::*;
+use std::io::BufReader;
+use std::io::{Error, ErrorKind};
+
+fn find_product_2(numbers: &Vec<i64>) -> Result<i64, Error> {
+ // find the two entries that sum to 2020 and multiply them
+ for i in numbers.iter() {
+ for j in numbers.iter() {
+ if (i + j) == 2020 {
+ return Ok(i * j);
+ }
+ }
+ }
+ Err(Error::new(
+ ErrorKind::Other,
+ "No entries found summing to 2020",
+ ))
+}
+
+fn find_product_3(numbers: &Vec<i64>) -> Result<i64, Error> {
+ // find the three entries that sum to 2020 and multiply them
+ for i in numbers.iter() {
+ for j in numbers.iter() {
+ for k in numbers.iter() {
+ if (i + j + k) == 2020 {
+ return Ok(i * j * k);
+ }
+ }
+ }
+ }
+ Err(Error::new(
+ ErrorKind::Other,
+ "No entries found summing to 2020",
+ ))
+}
+
+fn main() -> Result<(), Error> {
+ // read all the numbers in
+ let input = File::open("input.txt")?;
+ let reader = BufReader::new(input);
+ let mut numbers: Vec<i64> = Vec::new();
+ for l in reader.lines() {
+ let line = l?;
+ if line.len() < 1 {
+ continue;
+ }
+ let i: i64 = line
+ .parse()
+ .map_err(|e| Error::new(ErrorKind::Other, format!("{:?}", e)))?;
+ numbers.push(i);
+ }
+
+ let result2 = find_product_2(&numbers)?;
+ println!("Found the answer for 2! {}", result2);
+
+ let result3 = find_product_3(&numbers)?;
+ println!("Found the answer for 3! {}", result3);
+ Ok(())
+}