|
|
|
@ -1,3 +1,6 @@
|
|
|
|
|
#![feature(test)]
|
|
|
|
|
extern crate test;
|
|
|
|
|
|
|
|
|
|
const INPUT: &'static str = include_str!("../inputs/day1.txt");
|
|
|
|
|
|
|
|
|
|
fn depths() -> Vec<u64> {
|
|
|
|
@ -8,15 +11,39 @@ fn depths() -> Vec<u64> {
|
|
|
|
|
.collect()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
let days = depths();
|
|
|
|
|
fn solution(depths: &[u64]) -> i32 {
|
|
|
|
|
let mut count = 0;
|
|
|
|
|
|
|
|
|
|
for set in days.windows(2) {
|
|
|
|
|
if set[1] > set[0] {
|
|
|
|
|
// For a window size of 3, We can consider a window size of 4
|
|
|
|
|
// A + B + C && B + C + D
|
|
|
|
|
// Since B, C are shared between the two consecutive sets,
|
|
|
|
|
// We only need to compare A and D
|
|
|
|
|
for set in depths.windows(4) {
|
|
|
|
|
if set[0] < set[3] {
|
|
|
|
|
count += 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
count
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
let depths = &depths();
|
|
|
|
|
let count = solution(depths);
|
|
|
|
|
println!("increased {} times", count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
|
fn solution_bench(b: &mut test::Bencher) {
|
|
|
|
|
let depths = depths();
|
|
|
|
|
|
|
|
|
|
b.iter(|| {
|
|
|
|
|
let v = solution(&depths);
|
|
|
|
|
test::black_box(v);
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn solution_test() {
|
|
|
|
|
assert_eq!(solution(&depths()), 1429);
|
|
|
|
|
}
|
|
|
|
|