summaryrefslogtreecommitdiff
path: root/src/solvers/bwinf.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/solvers/bwinf.rs')
-rw-r--r--src/solvers/bwinf.rs47
1 files changed, 33 insertions, 14 deletions
diff --git a/src/solvers/bwinf.rs b/src/solvers/bwinf.rs
index 2049acc..dbcbea9 100644
--- a/src/solvers/bwinf.rs
+++ b/src/solvers/bwinf.rs
@@ -1,3 +1,5 @@
+use super::{Solver, FirstSolver};
+
#[derive(Clone, Debug)]
struct Row {
n: u32,
@@ -90,7 +92,7 @@ impl Row {
}
#[derive(Clone, Debug)]
-pub struct Wall {
+pub struct BwinfSolver {
n: u32,
h: u32,
b: u32,
@@ -98,12 +100,12 @@ pub struct Wall {
x: u32,
min_max_reachable: u32,
max_reached: u32,
- steps: u32,
+ steps: u64
}
-impl Wall {
- pub fn new(n: u32) -> Self {
- let (h, b) = ((n >> 1) + 1, (n * n + n) >> 1);
+impl Solver for BwinfSolver {
+ fn new(n: u32) -> Self {
+ let (h, b) = ((n >> 1) + 1, (n * n + n ) >> 1);
Self {
n,
h,
@@ -116,6 +118,24 @@ impl Wall {
}
}
+ fn n(&self) -> u32 {
+ self.n
+ }
+
+ fn h(&self) -> u32 {
+ self.h
+ }
+
+ fn w(&self) -> u32 {
+ self.b
+ }
+}
+
+impl BwinfSolver {
+ pub fn solve(&mut self) {
+ self.solve_recursive();
+ }
+
fn new_linear(n: u32) -> Self {
let (h, b) = ((n >> 1) + 1, (n * n + n) >> 1);
let rows = (1..=h).map(|i| Row::with_stone(n, b, i)).collect();
@@ -147,7 +167,8 @@ impl Wall {
//(-max_stone, index)
let perc = (self.x as f32 / (self.b as f32)) * (self.h as f32);
let dif = (perc - (index as f32)).abs().round() as i32;
- (-max_stone, dif)
+ //(-max_stone, dif)
+ (index, 0)
}
fn order(&self) -> Vec<u32> {
@@ -158,7 +179,7 @@ impl Wall {
v*/
}
- pub fn solve(&mut self) -> bool {
+ fn solve_recursive(&mut self) -> bool {
self.steps += 1;
// complete if already nearly complete
if self.x == self.b {
@@ -182,7 +203,7 @@ impl Wall {
}
if self.min_max_reachable > self.x {
self.x += 1;
- if self.solve() {
+ if self.solve_recursive() {
return true;
}
self.x -= 1;
@@ -199,10 +220,8 @@ impl Wall {
row.output_numbers();
}
}
-}
-/*fn main() {
- let mut wall = Wall::new(26);
- wall.solve();
- wall.output();
-}*/
+ pub fn get_steps(&self) -> u64 {
+ self.steps
+ }
+}