-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
36 lines (31 loc) · 811 Bytes
/
main.rs
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
use itertools::Itertools;
fn part1(input: &str) -> usize {
input
.split('\n')
.map(|line| line.parse::<u32>().unwrap())
.tuple_windows::<(u32, u32)>()
.filter(|(a, b)| b > a)
.count()
}
fn part2(input: &str) -> usize {
input
.split('\n')
.map(|line| line.parse::<u32>().unwrap())
.tuple_windows::<(u32, u32, u32)>()
.map(|(a, b, c)| a + b + c)
.tuple_windows::<(u32, u32)>()
.filter(|(a, b)| b > a)
.count()
}
fn main() {
println!("Part 1: {}", part1(include_str!("in.txt")));
println!("Part 2: {}", part2(include_str!("in.txt")));
}
#[test]
fn test_part1() {
assert_eq!(part1(include_str!("test.txt")), 7);
}
#[test]
fn test_part2() {
assert_eq!(part2(include_str!("test.txt")), 5);
}