This commit is contained in:
2022-12-01 19:08:18 +00:00
commit 428b3da1d9
5 changed files with 48 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
/target
Generated
+7
View File
@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "d1"
version = "0.1.0"
+8
View File
@@ -0,0 +1,8 @@
[package]
name = "d1"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
+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(())
}