[rs] Simplify 2022_01
This commit is contained in:
parent
569e659342
commit
5c17b5a556
1 changed files with 10 additions and 18 deletions
|
|
@ -1,22 +1,14 @@
|
|||
pub fn solve(input: String) -> anyhow::Result<()> {
|
||||
let mut elves = vec![];
|
||||
let mut elf = vec![];
|
||||
for line in input.lines() {
|
||||
if let Ok(number) = line.trim().parse::<u32>() {
|
||||
elf.push(number);
|
||||
} else {
|
||||
elves.push(elf);
|
||||
elf = vec![];
|
||||
}
|
||||
}
|
||||
if !elf.is_empty() {
|
||||
elves.push(elf);
|
||||
}
|
||||
|
||||
let mut elves = elves
|
||||
.into_iter()
|
||||
.map(|e| e.into_iter().sum())
|
||||
.collect::<Vec<u32>>();
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue