-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path03.rs
35 lines (29 loc) · 750 Bytes
/
03.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
#![feature(test)]
type Input = Vec<String>;
fn setup(input: &str) -> Input {
input.lines().map(|s| s.to_string()).collect()
}
fn cnt_slope(input: &Input, dx: u64, dy: u64) -> u64 {
let mut out = 0;
let mut x = 0;
let mut y = 0;
while y < input.len() {
if input[y].chars().nth(x % input[y].len()).unwrap() == '#' {
out += 1;
}
x += dx as usize;
y += dy as usize;
}
out
}
fn part1(input: &Input) -> String {
cnt_slope(input, 3, 1).to_string()
}
fn part2(input: &Input) -> String {
[(1, 1), (3, 1), (5, 1), (7, 1), (1, 2)]
.iter()
.map(|&(dx, dy)| cnt_slope(input, dx, dy))
.product::<u64>()
.to_string()
}
aoc::main!(2020, 3, ex: 1);