Skip to content

Commit b6fd8bf

Browse files
committed
fix(06/2015): fix bug with turn off to zero and solve second part
1 parent 012efb2 commit b6fd8bf

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
| [Day 3: Perfectly Spherical Houses in a Vacuum](src/solutions/year2015/day03.rs) | ⭐⭐ | 0.358 | 0.373 |
9393
| [Day 4: The Ideal Stocking Stuffer](src/solutions/year2015/day04.rs) | ⭐⭐ | 66.769 | 1931.428 |
9494
| [Day 5: Doesn't He Have Intern-Elves For This?](src/solutions/year2015/day05.rs) | ⭐⭐ | 0.261 | 0.987 |
95-
| [Day 6: Probably a Fire Hazard](src/solutions/year2015/day06.rs) | | 1227.077 | - |
95+
| [Day 6: Probably a Fire Hazard](src/solutions/year2015/day06.rs) | | 1227.077 | 1580.565 |
9696

9797
# TODO
9898

src/solutions/year2015/day06.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl Instruction for TurnOff {
112112
}
113113

114114
fn apply_part_two(&self, grid: &mut Grid<u64>) {
115-
grid.modify_many_with(self.surface_range.points(), |b| *b = u64::max(*b - 1, 0))
115+
grid.modify_many_with(self.surface_range.points(), |b| *b = if *b == 0 { 0 } else { *b - 1})
116116
}
117117
}
118118

@@ -155,5 +155,14 @@ mod tests {
155155
fn part_two_example_test() {
156156
assert_eq!("1", Day06.part_two("turn on 0,0 through 0,0"));
157157
assert_eq!("2000000", Day06.part_two("toggle 0,0 through 999,999"));
158+
assert_eq!("7", Day06.part_two(r#"toggle 0,0 through 0,3
159+
turn off 0,0 through 0,0"#));
160+
assert_eq!("6", Day06.part_two(r#"toggle 0,0 through 0,3
161+
turn off 0,0 through 0,0
162+
turn off 0,0 through 0,0"#));
163+
assert_eq!("6", Day06.part_two(r#"toggle 0,0 through 0,3
164+
turn off 0,0 through 0,0
165+
turn off 0,0 through 0,0
166+
turn off 0,0 through 0,0"#));
158167
}
159168
}

0 commit comments

Comments
 (0)