Files
aoc22/day01/src/main1.rs
2024-03-12 22:42:38 -07:00

26 lines
597 B
Rust

use std::env;
use std::fs::File;
use std::io::BufReader;
use std::io::BufRead;
fn main() {
let args: Vec<String> = env::args().collect();
let input = &args[1];
let reader = BufReader::new(File::open(input).expect("where file?"));
let mut sum: i64 = 0;
let mut max: i64 = 0;
for line in reader.lines() {
if !line.as_ref().unwrap().trim().is_empty() {
sum += line.unwrap().parse::<i64>().unwrap();
} else {
if sum > max {
max = sum;
}
sum = 0;
}
}
println!("Max: {}", max);
}