Works for problem 1
This commit is contained in:
parent
70d09f4f08
commit
edf113b698
20
src/main.rs
20
src/main.rs
@ -1,3 +1,21 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
println!("Hello, world!");
|
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}");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user