Codinget 2 years ago
commit 428b3da1d9
  1. 1
      .gitignore
  2. 1
      d1/.gitignore
  3. 7
      d1/Cargo.lock
  4. 8
      d1/Cargo.toml
  5. 31
      d1/src/main.rs

1
.gitignore vendored

@ -0,0 +1 @@
input.txt

1
d1/.gitignore vendored

@ -0,0 +1 @@
/target

7
d1/Cargo.lock generated

@ -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"

@ -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]

@ -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(())
}
Loading…
Cancel
Save