aboutsummaryrefslogtreecommitdiff
path: root/src/day1.rs
blob: e5dd408b398a3a7d5bd49aaa332881a61a753f93 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use aoc_runner_derive::*;
use std::str::FromStr;

#[aoc_generator(day1)]
pub fn input_generator<'c>(input : &'c str) -> Vec<u32>{ 
    input.lines().map(u32::from_str).map(Result::unwrap).collect()
}

#[aoc(day1, part1)]
pub fn solve_part1(input : &Vec<u32>) -> u32 {
    struct Helper {
        count : u32,
        prev : u32,
    }
    input.iter().fold(Helper{count:0,prev:u32::MAX},|x ,curr| -> Helper {if curr > &x.prev {Helper{count : x.count + 1, prev : *curr}} else {Helper{count : x.count, prev : *curr}}}).count
}