summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs2
-rw-r--r--src/solvers.rs8
2 files changed, 5 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs
index d698bd6..9f15fd8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3,5 +3,5 @@ mod solvers;
fn main() {
let mut solver = solvers::Solver::<u8>::new(2);
let wall = solver.solve();
- wall.output(solver.w, solver.h);
+ wall.output(solver.n, solver.h);
}
diff --git a/src/solvers.rs b/src/solvers.rs
index 99cbba7..9bf0ad6 100644
--- a/src/solvers.rs
+++ b/src/solvers.rs
@@ -18,9 +18,9 @@ impl Wall {
}
pub fn calculate_row(&self, r: u32, stones: &mut [u32]) {
- let mut len = 0;
+ let mut len = 1;
let mut i = 0;
- for &height in self.heights.iter() {
+ for &height in self.heights.iter().chain([r].iter()) {
if height == r {
stones[i] = len;
i += 1;
@@ -30,8 +30,8 @@ impl Wall {
}
}
- pub fn output(&self, w: u32, h: u32) {
- let mut stones = vec![0; w as usize];
+ pub fn output(&self, n: u32, h: u32) {
+ let mut stones = vec![0; n as usize];
for row in 0..h {
self.calculate_row(row, &mut stones);
for &len in stones.iter() {