From b01111bde9e5a7818b995d61bb3e4032bb443b52 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Fri, 20 Dec 2019 06:15:33 +0100 Subject: Add geric types to store the data in --- Cargo.toml | 1 + src/main.rs | 2 +- src/solvers.rs | 23 ++++++++++++++++------- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 556ee99..9d312e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,3 +7,4 @@ edition = "2018" [dependencies] +num = "0.2" 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::::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 { + 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, } -impl Solver { - pub fn new(n: u32) -> Self { +impl Solver { + 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) } } - -- cgit v1.2.3-54-g00ecf