You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
577 B
29 lines
577 B
use std::error;
|
|
use std::fs::File;
|
|
use std::io::BufRead;
|
|
use std::io::BufReader;
|
|
|
|
|
|
fn main() -> Result<(), Box<dyn error::Error>> {
|
|
let f = File::open("input.txt")?;
|
|
let reader = BufReader::new(f);
|
|
|
|
let mut sums: Vec<u32> = Vec::new();
|
|
let mut current_sum: u32 = 0;
|
|
for value in reader.lines() {
|
|
let value = value.unwrap();
|
|
if value == "" {
|
|
sums.push(current_sum);
|
|
current_sum = 0;
|
|
} else {
|
|
current_sum += value.parse::<u32>()?;
|
|
}
|
|
}
|
|
sums.push(current_sum);
|
|
sums.sort();
|
|
sums.reverse();
|
|
|
|
println!("{:?}", sums[..3].iter().sum::<u32>());
|
|
Ok(())
|
|
}
|