solve problem 1

This commit is contained in:
Adam Jeniski 2022-01-07 03:00:45 -05:00
parent 8bc687743d
commit 26544fc9a3

20
src/day1.rs Normal file → Executable file
View File

@ -1,7 +1,21 @@
fn part_1_solution(input: &str) -> u64 { #![allow(dead_code)]
todo!(); fn parse_input(input: &str) -> Vec<u32> {
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)] #[cfg(test)]