diff options
author | Andreas Grois <andi@grois.info> | 2021-12-02 18:47:14 +0100 |
---|---|---|
committer | Andreas Grois <andi@grois.info> | 2021-12-02 18:47:14 +0100 |
commit | 48e7a6537dc2b0411db18705af5c95062a901d03 (patch) | |
tree | f9049a6a06712feaa6e1a489705c55fcdb22aa49 /src/day1.rs |
Initial
Diffstat (limited to 'src/day1.rs')
-rw-r--r-- | src/day1.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/day1.rs b/src/day1.rs new file mode 100644 index 0000000..e5dd408 --- /dev/null +++ b/src/day1.rs @@ -0,0 +1,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 +} |