2021-12-01 06:26:45 +01:00
#![ feature(array_windows) ]
2021-12-01 06:19:33 +01:00
#![ feature(test) ]
extern crate test ;
use aoc2021 ::common ::{ parse_nums , * } ;
2021-12-02 10:31:23 +01:00
const DAY : usize = 1 ;
2021-12-01 06:19:33 +01:00
type Parsed = Vec < usize > ;
fn parse_input ( raw : & str ) -> Parsed {
parse_nums ( raw )
}
fn part1 ( parsed : & Parsed ) -> usize {
2021-12-01 06:26:45 +01:00
parsed . array_windows ( ) . filter ( | [ a , b ] | a < b ) . count ( )
2021-12-01 06:19:33 +01:00
}
fn part2 ( parsed : & Parsed ) -> usize {
2021-12-01 06:26:45 +01:00
parsed . array_windows ( ) . filter ( | [ a , _ , _ , b ] | a < b ) . count ( )
2021-12-01 06:19:33 +01:00
}
fn main ( ) {
2021-12-02 10:31:23 +01:00
let input = parse_input ( & read_file ( DAY ) ) ;
2021-12-01 06:19:33 +01:00
println! ( " Part 1: {} " , part1 ( & input ) ) ;
println! ( " Part 2: {} " , part2 ( & input ) ) ;
}
#[ cfg(test) ]
mod tests {
use super ::* ;
use aoc2021 ::* ;
const TEST_INPUT : & str = " 199
200
208
210
200
207
240
269
260
263 " ;
test! ( part1 ( ) = = 7 ) ;
test! ( part2 ( ) = = 5 ) ;
bench! ( part1 ( ) = = 1316 ) ;
bench! ( part2 ( ) = = 1344 ) ;
bench_input! ( len = = 2000 ) ;
}