diff options
Diffstat (limited to 'src/day1.rs')
-rw-r--r-- | src/day1.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/day1.rs b/src/day1.rs new file mode 100644 index 0000000..8aa966b --- /dev/null +++ b/src/day1.rs @@ -0,0 +1,27 @@ +struct Foo { + acc: u32, + max: [u32;3], +} + +pub fn run(input: String) { + let init = Foo{ + acc: 0, + max: [0,0,0], + }; + let res = input.lines().fold(init, |foo, line| { + return if line.is_empty() { + let mut arr = [foo.acc, foo.max[0], foo.max[1], foo.max[2]]; + arr.sort(); + Foo { + acc: 0, + max: [arr[1], arr[2], arr[3]], + } + } else { + Foo { + acc: foo.acc + line.parse::<u32>().expect("input line wasn't a u32!"), + max: foo.max, + } + } + }); + println!("day 1: {}", res.max.into_iter().sum::<u32>()); +}
\ No newline at end of file |