[rust] Use a Box for the light grid
change
commit 2e0e26f720e24372f6152d3aba5a9dd2c3465df3
author Alpha Chen <alpha.chen@gmail.com>
date
parent 2878ceb4
diff --git a/rust/src/day_06.rs b/rust/src/day_06.rs
index f8ae446..d8fbd6d 100644
--- a/rust/src/day_06.rs
+++ b/rust/src/day_06.rs
@@ -31,12 +31,12 @@ fn test_solve() {
 }
 
 struct LightGrid {
-    grid: [[bool; 1_000]; 1_000],
+    grid: Box<[bool; 1_000 * 1_000]>,
 }
 
 impl LightGrid {
     fn new() -> LightGrid {
-        LightGrid { grid: [[false; 1_000]; 1_000] }
+        LightGrid { grid: Box::new([false; 1_000 * 1_000]) }
     }
 
     fn turn_on(&mut self, rect: Rect) {
@@ -90,13 +90,13 @@ impl Index<Point> for LightGrid {
     type Output = bool;
 
     fn index(&self, _index: Point) -> &bool {
-        &self.grid[_index.0][_index.1]
+        &self.grid[1_000 * _index.0 + _index.1]
     }
 }
 
 impl IndexMut<Point> for LightGrid {
     fn index_mut(&mut self, _index: Point) -> &mut bool {
-        &mut self.grid[_index.0][_index.1]
+        &mut self.grid[1_000 * _index.0 + _index.1]
     }
 }