diff --git a/src/day1.rs b/src/day1.rs old mode 100644 new mode 100755 index e25f57b..f24df0f --- a/src/day1.rs +++ b/src/day1.rs @@ -1,7 +1,21 @@ -fn part_1_solution(input: &str) -> u64 { - +#![allow(dead_code)] - todo!(); +fn parse_input(input: &str) -> Vec { + input.split_ascii_whitespace().map(|x| x.parse().unwrap() ).collect() +} + +fn part_1_solution(input: &str) -> u64 { + parse_input(input) + .as_slice() + .windows(2) + .fold(0, |acc, w| if w[0] < w[1] { acc + 1 } else { acc }) +} + +fn part_2_solution(input: &str) -> u64 { + parse_input(input) + .as_slice() + .windows(4) + .fold(0, |acc, w| if w[0] < w[3] { acc + 1 } else { acc }) } #[cfg(test)]