-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday01.rs
57 lines (50 loc) · 1.19 KB
/
day01.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
pub fn part_one(input: &str) -> u32 {
input
.split("\n\n")
.map(|l| {
l.lines()
.map(str::parse::<u32>)
.map(std::result::Result::unwrap)
.sum::<u32>()
})
.max()
.unwrap()
}
pub fn part_two(input: &str) -> u32 {
let mut vals = input
.split("\n\n")
.map(|l| {
l.lines()
.map(str::parse::<u32>)
.map(std::result::Result::unwrap)
.sum::<u32>()
})
.collect::<Vec<_>>();
vals.sort();
vals.iter().rev().take(3).sum::<u32>()
}
#[cfg(test)]
mod tests {
#[test]
fn part_one_example() {
assert_eq!(
super::part_one(include_str!("input/day01_example.txt")),
24000
);
}
#[test]
fn part_one() {
assert_eq!(super::part_one(include_str!("input/day01.txt")), 70764);
}
#[test]
fn part_two_example() {
assert_eq!(
super::part_two(include_str!("input/day01_example.txt")),
45000
);
}
#[test]
fn part_two() {
assert_eq!(super::part_two(include_str!("input/day01.txt")), 203905);
}
}