1
0
Fork 0

Works for problem 1

This commit is contained in:
Pcornat 2022-12-01 22:09:13 +01:00
parent 70d09f4f08
commit edf113b698
Signed by: Pcornat
GPG Key ID: 2F3932FF46D9ECA0
2 changed files with 2263 additions and 1 deletions

2244
input.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,21 @@
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}");
}