[rs] Move 2022_01 solution to y2022 module
This commit is contained in:
parent
214eb5b258
commit
ff0ebe393b
3 changed files with 3 additions and 2 deletions
23
rs/src/y2022/d01.rs
Normal file
23
rs/src/y2022/d01.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
pub fn solve(input: String) -> anyhow::Result<()> {
|
||||
let mut elves = input
|
||||
.trim()
|
||||
.split("\n\n")
|
||||
.map(|chunk| {
|
||||
chunk
|
||||
.split('\n')
|
||||
.map(|n| n.parse::<u32>().unwrap())
|
||||
.sum::<u32>()
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
elves.sort_unstable();
|
||||
|
||||
// Part 1
|
||||
let top = elves.last().unwrap();
|
||||
println!("Part 1: {top}");
|
||||
|
||||
// Part 2
|
||||
let top_three = elves.iter().rev().take(3).sum::<u32>();
|
||||
println!("Part 2: {top_three}");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue