-
Notifications
You must be signed in to change notification settings - Fork 0
/
part2.rs
37 lines (30 loc) · 862 Bytes
/
part2.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
use super::*;
type OutputType = super::part1::OutputType;
pub fn solve(input: &InputType) -> OutputType {
let (max_sleepminute, max_sleeper) = {
let mut max_sleepminute = 0;
let mut max_sleeper = 0;
for (id, guard) in input.iter() {
let sleepminute = guard.get_max_sleepminute();
if sleepminute > max_sleepminute {
max_sleepminute = sleepminute;
max_sleeper = *id;
}
}
(max_sleepminute, max_sleeper)
};
max_sleepminute * max_sleeper
}
#[cfg(test)]
mod tests {
use super::*;
fn solve_example(name: &str) -> OutputType {
let input = parse_input(name, false);
let guards = precompute(input);
solve(&guards)
}
#[test]
fn examples() {
assert_eq!(solve_example("example1"), 4455);
}
}