Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

unindent some code; better testing

  • Loading branch information...
commit 394a64126c7b9456d12007dc05db8f4f79804937 1 parent 625410a
@moritz authored
Showing with 13 additions and 14 deletions.
  1. +6 −7 lib/Nonogram.pm
  2. +7 −7 t/solving.t
View
13 lib/Nonogram.pm
@@ -201,6 +201,12 @@ class Nonogram {
}
method solve-gen() {
+ sub distribute($total, $cells) {
+ return [$total] if $cells == 1;
+ gather for 0..$total -> $c {
+ take [$c, $_.flat] for distribute($total - $c, $cells - 1);
+ }
+ }
for <h v> -> $direction {
my $total = $direction eq 'h'
?? @.colspec.elems
@@ -231,13 +237,6 @@ class Nonogram {
@.field-rows[$v.from][$idx] = ~$v;
}
}
-
- sub distribute($total, $cells) {
- return [$total] if $cells == 1;
- gather for 0..$total -> $c {
- take [$c, $_.flat] for distribute($total - $c, $cells - 1);
- }
- }
}
}
}
View
14 t/solving.t
@@ -13,19 +13,19 @@ my $n = Nonogram.new(
lives_ok { $n.solve() }, 'can run .solve';
-my $solved =
-q[1111111|
-10000001|
+my $solved = q[
+11111111|
+12222111|
12222221|
-12210001|
-12210001|
+12211221|
+12211221|
12222221|
12222111|
12211111|
12211111|
-10000001|
+12211111|
11111111|];
-for $solved.split("\n").kv -> $j, $line {
+for $solved.trim.split("\n").kv -> $j, $line {
my $i = 0;
for $line.comb -> $c {
if $c eq any <1 2> {
Please sign in to comment.
Something went wrong with that request. Please try again.