1
0
Fork 0

Switch to match and do cargo fmt

This commit is contained in:
Vivianne 2022-11-30 22:55:46 -08:00
parent 30aea9de13
commit 7b5d96c21e
1 changed files with 15 additions and 8 deletions

View File

@ -1,6 +1,6 @@
use std::collections::BinaryHeap;
use std::fs;
use std::io::{self, BufRead};
use std::collections::BinaryHeap;
fn main() {
let filename = "etc/p01.txt";
@ -10,13 +10,20 @@ fn main() {
let mut heap = BinaryHeap::new();
let mut cur_cals: u32 = 0;
for l in lines {
if let Ok(cals) = l.expect("Can't read line.").parse::<u32>() {
cur_cals += cals;
} else {
heap.push(cur_cals);
println!("new cals: {}, max so far: {}", cur_cals, heap.peek().expect("Can't peek from heap!"));
cur_cals = 0;
};
match l.expect("Can't read line.").parse::<u32>() {
Ok(cals) => {
cur_cals += cals;
}
_ => {
heap.push(cur_cals);
println!(
"new cals: {}, max so far: {}",
cur_cals,
heap.peek().expect("Can't peek from heap!")
);
cur_cals = 0;
}
}
}
if cur_cals > 0 {