diff --git a/src/bin/p01.rs b/src/bin/p01.rs index 3ae9b05..d1ab649 100644 --- a/src/bin/p01.rs +++ b/src/bin/p01.rs @@ -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::() { - 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::() { + 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 {