Day 1
parent
30f08891dc
commit
7b19a53f66
File diff suppressed because it is too large
Load Diff
|
@ -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(());
|
||||
}
|
|
@ -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(());
|
||||
}
|
Loading…
Reference in New Issue