18 lines
497 B
Rust
18 lines
497 B
Rust
|
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
|
||
|
}
|