mirror of
https://github.com/Ajetski/advent-of-code.git
synced 2025-09-30 09:33:19 -09:00
solve problem 1
This commit is contained in:
parent
8bc687743d
commit
26544fc9a3
20
src/day1.rs
Normal file → Executable file
20
src/day1.rs
Normal file → Executable 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)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user