summaryrefslogtreecommitdiff
path: root/src/solvers
diff options
context:
space:
mode:
Diffstat (limited to 'src/solvers')
-rw-r--r--src/solvers/bwinf.rs47
-rw-r--r--src/solvers/mod.rs8
2 files changed, 35 insertions, 20 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
+ }
+}
diff --git a/src/solvers/mod.rs b/src/solvers/mod.rs
index 84e9642..0ea589b 100644
--- a/src/solvers/mod.rs
+++ b/src/solvers/mod.rs
@@ -2,10 +2,6 @@
pub mod gpu;
pub mod gpusolver;
pub mod bwinf;
-//pub mod single;
-
-//use crate::structs::StoneWall;
-pub use gpu::*;
/// calculate h and w
pub fn wall_stats(n: u32) -> (u32, u32) {
@@ -21,10 +17,10 @@ pub trait Solver {
}
pub trait FirstSolver {
- fn solve(self) -> RowResult;
+ fn solve(self) -> gpu::RowResult;
}
pub trait IteratorSolver: Solver {
- type IntoIter: Iterator<Item = RowResult>;
+ type IntoIter: Iterator<Item = gpu::RowResult>;
fn solve(self) -> Self::IntoIter;
}