-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.rs
More file actions
37 lines (34 loc) · 831 Bytes
/
main.rs
File metadata and controls
37 lines (34 loc) · 831 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
use std::fs;
fn main() {
let input = fs::read_to_string("input.txt").expect("Could not read file");
let layers = input
.lines()
.map(|l| {
let (layer, len) = l.split_once(": ").unwrap();
(
layer.parse::<usize>().unwrap(),
len.parse::<usize>().unwrap(),
)
})
.collect::<Vec<_>>();
// part 1
let mut severity = 0;
for l in &layers {
if l.0 % (l.1 * 2 - 2) == 0 {
severity += l.0 * l.1;
}
}
println!("{severity}");
// part 2
let mut delay = 0;
'outer: loop {
delay += 1;
for l in &layers {
if (delay + l.0) % (l.1 * 2 - 2) == 0 {
continue 'outer;
}
}
break;
}
println!("{delay}");
}