commit
428b3da1d9
@ -0,0 +1 @@ |
||||
input.txt |
@ -0,0 +1 @@ |
||||
/target |
@ -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…
Reference in new issue