-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpart2.rs
44 lines (36 loc) · 945 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
38
39
40
41
42
43
44
use super::*;
use super::part1::OutputType;
pub fn solve(input: &InputType) -> OutputType {
let mut grid = vec![vec![0usize; 1000]; 1000];
let mut broken = Vec::new();
for claim in input.iter() {
for ii in claim.left..claim.left+claim.width {
for jj in claim.top..claim.top + claim.height {
if grid[ii][jj] != 0 {
broken.push(grid[ii][jj]);
broken.push(claim.id);
}
grid[ii][jj] = claim.id;
}
}
}
broken.dedup();
for claim in input {
if ! broken.contains(&claim.id) {
return claim.id;
}
}
0
}
#[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"), 3);
}
}