[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<()> {
|
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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue