-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday01.rs
More file actions
40 lines (35 loc) · 861 Bytes
/
day01.rs
File metadata and controls
40 lines (35 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use aoc_runner_derive::{aoc, aoc_generator};
#[aoc_generator(day1)]
fn parse_input(input: &str) -> Vec<i32> {
input.lines().map(|l| l.parse::<i32>().unwrap()).collect()
}
#[aoc(day1, part1)]
fn part1(input: &[i32]) -> usize {
input
.iter()
.zip(input.iter().skip(1))
.filter(|(a, b)| b > a)
.count()
}
#[aoc(day1, part2)]
fn part2(input: &[i32]) -> usize {
input
.iter()
.zip(input.iter().skip(3))
.filter(|(a, b)| b > a)
.count()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn sample1() {
let input = vec![199, 200, 208, 210, 200, 207, 240, 269, 260, 263];
assert_eq!(part1(&input), 7);
}
#[test]
fn sample2() {
let input = vec![199, 200, 208, 210, 200, 207, 240, 269, 260, 263];
assert_eq!(part2(&input), 5);
}
}