summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs10
-rw-r--r--src/solvers/bwinf.rs39
-rw-r--r--src/solvers/mod.rs4
3 files changed, 34 insertions, 19 deletions
diff --git a/src/main.rs b/src/main.rs
index 674d139..299dbc3 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3,8 +3,10 @@ mod solvers;
mod structs;
use crate::solvers::{IteratorSolver, Solver};
-pub static N: u32 = 8;
+pub static N: u32 = 30;
fn main() {
+ let clock = std::time::Instant::now();
+
//let mut solver = solvers::single::NormalSolver::new(N);
//solver.solve();
//let solver = solvers::gpusolver::GpuSolver::new(N);
@@ -12,7 +14,9 @@ fn main() {
/*for (i, solution) in solver.solve().enumerate() {
println!("{}: {:?}", i, solution);
}*/
- let mut wall = solvers::bwinf::Wall::new(26);
+ let mut wall = solvers::bwinf::Wall::new(N);
wall.solve();
- wall.output()
+ wall.output();
+
+ println!("took: {:?}", clock.elapsed());
}
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
+ }
+}
diff --git a/src/solvers/mod.rs b/src/solvers/mod.rs
index 84e9642..8fdd296 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) {