Skip to content

Instantly share code, notes, and snippets.

@social-anthrax
Last active December 1, 2021 15:30
Show Gist options
  • Save social-anthrax/4d3fa008c7b7ef5f6fd724ac17dd73a5 to your computer and use it in GitHub Desktop.
Save social-anthrax/4d3fa008c7b7ef5f6fd724ac17dd73a5 to your computer and use it in GitHub Desktop.
solutions for day one of advent of code
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