1
0
mirror of https://gitlab.com/MisterBiggs/aoc2020.git synced 2025-06-15 13:56:39 +00:00

day1 in rust

This commit is contained in:
Anson 2021-01-09 00:57:38 -07:00
parent 9131a62377
commit 392657fda3
2 changed files with 35 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
main.pdb
main.exe

33
day1/main.rs Normal file
View File

@ -0,0 +1,33 @@
use std::fs;
fn main() {
let input = fs::read_to_string("day1\\input.txt").expect("Could not read file");
let lines: Vec<&str> = input.lines().collect();
println!("Part1:");
'outer1: for i in lines.iter() {
let l1 = i.parse::<i32>().unwrap();
for j in lines.iter() {
let l2 = j.parse::<i32>().unwrap();
if l1 + l2 == 2020 {
println!("{}+{} = 2020\nProduct {}", l1, l2, l1 * l2);
break 'outer1;
}
}
}
println!("\nPart2:");
'outer2: for i in lines.iter() {
let l1 = i.parse::<i32>().unwrap();
for j in lines.iter() {
let l2 = j.parse::<i32>().unwrap();
for k in lines.iter() {
let l3 = k.parse::<i32>().unwrap();
if l1 + l2 + l3 == 2020 {
println!("{}+{}+{} = 2020\nProduct {}", l1, l2, l3, l1 * l2 * l3);
break 'outer2;
}
}
}
}
}