summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Kobert <dennis@kobert.dev>2019-12-20 06:15:33 +0100
committerDennis Kobert <dennis@kobert.dev>2019-12-20 06:15:33 +0100
commitb01111bde9e5a7818b995d61bb3e4032bb443b52 (patch)
treecdd5a1bd769d189b196ed6ff4b12451fc100b303
parent104d5004bf269e2261f956291b416d60d3a270e0 (diff)
Add geric types to store the data in
-rw-r--r--Cargo.toml1
-rw-r--r--src/main.rs2
-rw-r--r--src/solvers.rs23
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::<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)
}
}
-