-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpart1.rs
41 lines (33 loc) · 799 Bytes
/
part1.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
use super::*;
pub type OutputType = usize;
pub fn solve(input: &InputType) -> OutputType {
let mut grid = vec![vec![0usize; 1000]; 1000];
for claim in input {
for ii in claim.left..claim.left+claim.width {
for jj in claim.top..claim.top + claim.height {
grid[ii][jj] += 1;
}
}
}
let mut counter = 0;
for row in grid.iter() {
for cell in row.iter() {
if *cell > 1 {
counter += 1;
}
}
}
counter
}
#[cfg(test)]
mod tests {
use super::*;
fn solve_example(name: &str) -> OutputType {
let input = parse_input(name, false);
solve(&input)
}
#[test]
fn examples() {
assert_eq!(solve_example("example1"), 4);
}
}