1
0
AdvenOfCode2022/src/prob1/mod.rs

18 lines
497 B
Rust
Raw Normal View History

2022-12-01 22:18:54 +01:00
pub fn solve(file_path: &str) -> i32 {
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;
}
});
max
}