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.rs39
1 files changed, 27 insertions, 12 deletions
diff --git a/src/solvers/bwinf.rs b/src/solvers/bwinf.rs
index fcf6876..8c9624b 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, b: u32,
@@ -87,17 +89,17 @@ impl Row {
}
#[derive(Clone, Debug)]
-pub struct Wall {
+pub struct BwinfSolver {
n: u32, h: u32, b: u32,
rows: Vec<Row>,
x: u32,
min_max_reachable: u32,
max_reached: u32,
- steps: u32
+ steps: u64
}
-impl Wall {
- pub fn new(n: u32) -> Self {
+impl Solver for BwinfSolver {
+ fn new(n: u32) -> Self {
let (h, b) = ((n >> 1) + 1, (n * n + n ) >> 1);
Self {
n, h, b,
@@ -109,6 +111,20 @@ impl Wall {
}
}
+ fn n(&self) -> u32 {
+ self.n
+ }
+
+ fn h(&self) -> u32 {
+ self.h
+ }
+
+ fn w(&self) -> u32 {
+ self.b
+ }
+}
+
+impl BwinfSolver {
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();
@@ -138,7 +154,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> {
@@ -149,7 +166,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 {
@@ -191,10 +208,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
+ }
+}