master
kalle 2022-12-01 11:58:44 +01:00
parent 30f08891dc
commit 7b19a53f66
3 changed files with 2314 additions and 0 deletions

2249
input/01.txt Normal file

File diff suppressed because it is too large Load Diff

30
src/bin/01_1.rs Normal file
View File

@ -0,0 +1,30 @@
#![feature(slice_group_by)]
use itertools::Itertools;
use itertools::max;
use std::fs;
use anyhow::Result;
fn main() -> Result<()> {
let input = fs::read_to_string("input/01.txt")?;
let groups = input
.split("\n").collect::<Vec<&str>>()
.into_iter()
.group_by(|ell| *ell != "");
let elves = groups
.into_iter()
.filter(|(key, _)| *key)
.map(|(_, elf)| elf
.into_iter()
.map(|val| val.parse::<i32>().unwrap())
.fold(0, |acc, val| acc + val)
);
let highest = max(elves);
println!("{:?}", highest);
return Ok(());
}

35
src/bin/01_2.rs Normal file
View File

@ -0,0 +1,35 @@
#![feature(slice_group_by)]
use itertools::Itertools;
use itertools::sorted;
use std::fs;
use anyhow::Result;
fn main() -> Result<()> {
let input = fs::read_to_string("input/01.txt")?;
let groups = input
.split("\n").collect::<Vec<&str>>()
.into_iter()
.group_by(|ell| *ell != "");
let elves: Vec<i32> = groups
.into_iter()
.filter(|(key, _)| *key)
.map(|(_, elf)| elf
.into_iter()
.map(|val| val.parse::<i32>().unwrap())
.sum()
).collect();
let highest = sorted(elves);
let sum: i32 = highest
.into_iter()
.rev()
.take(3)
.sum();
println!("{:?}", sum);
return Ok(());
}