This commit is contained in:
2022-12-01 19:08:18 +00:00
commit 428b3da1d9
5 changed files with 48 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
use std::fs::read_to_string;
use std::io::Error;
fn main() -> Result<(), Error> {
let mut max = 0;
let mut all = Vec::new();
let mut current = 0;
for line in read_to_string("input.txt")?.split("\n") {
if line == "" {
if current >= max {
max = current
}
all.push(current);
current = 0
} else {
current += line.parse::<u32>().unwrap()
}
}
if current >= max {
max = current
}
all.push(current);
all.sort_by(|a, b| b.cmp(a));
println!("part 1: {}", max);
println!("part 2: {}", all.iter().take(3).sum::<u32>());
Ok(())
}