Last active
December 2, 2022 09:40
-
-
Save dbarasti/6724261851732eb6041fefd381040111 to your computer and use it in GitHub Desktop.
First excercise of the AoC in functional Rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use itertools::Itertools; | |
use std::{ | |
fs::File, | |
io::{BufRead, BufReader}, | |
}; | |
fn main() -> std::io::Result<()> { | |
let f = File::open("test.txt")?; | |
let reader = BufReader::new(f); | |
let max = reader | |
.lines() | |
.map(|line| line.unwrap().parse::<i32>().unwrap_or(0)) | |
.group_by(|calories| *calories> 0) | |
.into_iter() | |
.map(|(_, backpack)| backpack.sum::<i32>()) | |
.max(); | |
if let Some(res) = max { | |
println!("{}", res); | |
} | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment