diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 2 | ||||
-rw-r--r-- | src/solvers.rs | 23 |
2 files changed, 17 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs index 53137e4..d698bd6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ mod solvers; fn main() { - let mut solver = solvers::Solver::new(2); + let mut solver = solvers::Solver::<u8>::new(2); let wall = solver.solve(); wall.output(solver.w, solver.h); } diff --git a/src/solvers.rs b/src/solvers.rs index a7cd481..99cbba7 100644 --- a/src/solvers.rs +++ b/src/solvers.rs @@ -39,7 +39,7 @@ impl Wall { print!("◼"); } else if len > 1 { print!("◢"); - for _ in 0..(len-2) { + for _ in 0..(len - 2) { print!("◼"); } print!("◣"); @@ -50,16 +50,26 @@ impl Wall { } } -pub struct Solver { - pub n: u32, pub h: u32, pub w: u32, +/// Solve for a given N and return the resulting wall +pub struct Solver<T: num::PrimInt> { + pub n: u32, + /// calculated height [might not be correct!] + pub h: u32, + /// width + pub w: u32, + /// Use to store already used blocks as a bitmask + solve_stack: Vec<T>, } -impl Solver { - pub fn new(n: u32) -> Self { +impl<T: num::PrimInt> Solver<T> { + pub fn new(n: usize) -> Self { let h = n / 2 + 1; let w = h * (n - 1); Self { - n, h, w + n: (n as u32), + h: (h as u32), + w: (w as u32), + solve_stack: Vec::with_capacity(n), } } @@ -67,4 +77,3 @@ impl Solver { Wall::create_empty(self.w) } } - |