1
0
Fork 0
AdvenOfCode2022/src/main.rs

22 lines
646 B
Rust
Raw Normal View History

2022-12-01 20:40:58 +01:00
fn main() {
2022-12-01 22:09:13 +01:00
let args: Vec<String> = std::env::args().collect();
let file_path = args
.get(1)
.expect("Please provide an argument on command-line.");
let contents =
std::fs::read_to_string(file_path).expect("Please provide a text file as an argument.");
let lines: Vec<&str> = contents.split("\n").collect();
let mut max = 0;
let mut accumulated = 0;
lines.iter().for_each(|number| {
if let Ok(yay) = number.parse::<i32>() {
accumulated += yay;
} else {
max = max.max(accumulated);
accumulated = 0;
}
});
println!("{max}");
2022-12-01 20:40:58 +01:00
}