Last active
December 1, 2021 15:30
-
-
Save social-anthrax/4d3fa008c7b7ef5f6fd724ac17dd73a5 to your computer and use it in GitHub Desktop.
solutions for day one of advent of code
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 crate::task_handler::get_task; | |
pub fn task1_1() -> String { | |
let input: Vec<usize> = get_task(1) | |
.lines() | |
.map(|x| x.parse::<usize>().unwrap()) | |
.collect(); | |
input.windows(2).filter(|x| x[0] < x[1]).count().to_string() | |
} | |
pub fn task1_2() -> String { | |
let input = get_task(1) | |
.lines() | |
.map(|x| x.parse::<usize>().unwrap()) | |
.collect(); | |
input | |
.windows(3) | |
.collect::<Vec<&[usize]>>() | |
.windows(2) | |
.filter(|x| x[0].iter().sum::<usize>() < x[1].iter().sum()) | |
.count() | |
.to_string() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment