summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/solvers.rs23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/solvers.rs b/src/solvers.rs
index 669fb6e..52ad4c1 100644
--- a/src/solvers.rs
+++ b/src/solvers.rs
@@ -37,7 +37,9 @@ impl Wall {
pub fn output(&self, n: u32, h: u32) {
let mut stones = vec![0; n as usize];
let mut toggle = 0;
- let colors = ["\x1b[31m", "\x1b[32m", "\x1b[33m", "\x1b[34m", "\x1b[35m", "\x1b[36m"];
+ let colors = [
+ "\x1b[31m", "\x1b[32m", "\x1b[33m", "\x1b[34m", "\x1b[35m", "\x1b[36m",
+ ];
for row in 0..h {
self.calculate_row(row, &mut stones);
for &len in stones.iter() {
@@ -71,11 +73,26 @@ impl<T: num::PrimInt> Solver<T> {
n: (n as u32),
h: (h as u32),
w: (w as u32),
- solve_stack: Vec::with_capacity(n),
+ solve_stack: vec![T::zero(); h],
}
}
pub fn solve(&mut self) -> Wall {
- Wall::create_empty(self.w)
+ let wall = Wall::create_empty(self.w);
+ wall.heights
+ .iter()
+ .take(2)
+ .zip(0..1)
+ .for_each(|(x, i)| self.set_stone(*x as usize, i));
+ wall
+ }
+
+ fn set_stone(&mut self, row: usize, stone: u32) {
+ self.solve_stack[row] =
+ self.solve_stack[row] | T::from(1 << stone).expect("Stone placing index out of bounds");
+ }
+
+ fn get_stone(&self, row: usize, stone: u32) {
+ self.solve_stack[row] & T::from(1 << stone).expect("Requested stone index out of bounds");
}
}