day1.rs (676B)
1 struct Foo { 2 acc: u32, 3 max: [u32;3], 4 } 5 6 pub fn run(input: String) { 7 let init = Foo{ 8 acc: 0, 9 max: [0,0,0], 10 }; 11 let res = input.lines().fold(init, |foo, line| { 12 return if line.is_empty() { 13 let mut arr = [foo.acc, foo.max[0], foo.max[1], foo.max[2]]; 14 arr.sort(); 15 Foo { 16 acc: 0, 17 max: [arr[1], arr[2], arr[3]], 18 } 19 } else { 20 Foo { 21 acc: foo.acc + line.parse::<u32>().expect("input line wasn't a u32!"), 22 max: foo.max, 23 } 24 } 25 }); 26 println!("day 1: {}", res.max.into_iter().sum::<u32>()); 27 }