[rs] Simplify 2022_01

This commit is contained in:
Joscha 2022-12-01 18:18:46 +01:00
parent 569e659342
commit 5c17b5a556

View file

@ -1,22 +1,14 @@
pub fn solve(input: String) -> anyhow::Result<()> { pub fn solve(input: String) -> anyhow::Result<()> {
let mut elves = vec![]; let mut elves = input
let mut elf = vec![]; .trim()
for line in input.lines() { .split("\n\n")
if let Ok(number) = line.trim().parse::<u32>() { .map(|chunk| {
elf.push(number); chunk
} else { .split('\n')
elves.push(elf); .map(|n| n.parse::<u32>().unwrap())
elf = vec![]; .sum::<u32>()
} })
} .collect::<Vec<_>>();
if !elf.is_empty() {
elves.push(elf);
}
let mut elves = elves
.into_iter()
.map(|e| e.into_iter().sum())
.collect::<Vec<u32>>();
elves.sort_unstable(); elves.sort_unstable();
// Part 1 // Part 1