01.rs
1 #![feature(test)] 2 3 type Input = Vec<i32>; 4 5 fn setup(input: &str) -> Input { 6 input.lines().map(|x| x.parse().unwrap()).collect() 7 } 8 9 fn count(input: &Input, window: usize) -> i32 { 10 let mut out = 0; 11 for (a, b) in input.iter().zip(&input[window..]) { 12 if b > a { 13 out += 1; 14 } 15 } 16 out 17 } 18 19 fn part1(input: &Input) -> String { 20 count(input, 1).to_string() 21 } 22 23 fn part2(input: &Input) -> String { 24 count(input, 3).to_string() 25 } 26 27 aoc::main!(2021, 1, ex: 1);