Permalink
Browse files

first primitive solving with position shifting

  • Loading branch information...
1 parent 4f800ed commit 0f70649341f97d94b43cf34653a68baad5e98772 @moritz committed Sep 5, 2010
Showing with 18 additions and 3 deletions.
  1. +18 −3 lib/Nonogram.pm
View
@@ -60,13 +60,14 @@ method Str {
method solve() {
# trivial cases first
$.solve-zero();
+ $.solve-one();
}
method solve-zero() {
- for @.colspec.kv -> $k, $v {
- if $v.elems == 0 {
+ for @.colspec.kv -> $idx, $col {
+ if $col.elems == 0 {
for @!field-rows {
- .[$k] = ' ';
+ .[$idx] = ' ';
}
}
}
@@ -77,4 +78,18 @@ method solve-zero() {
}
}
+method solve-one() {
+ for @.colspec.kv -> $idx, $col {
+ next unless $col.elems == 1;
+ my $c = $col[0];
+ my $overlaps = 2 * $c - @.rowspec;
+ if $overlaps > 0 {
+ my $lower = @.rowspec - $c;
+ my $upper = $lower + $overlaps - 1;
+ @!field-rows[$_][$idx] = '#' for $lower..$upper;
+ }
+ }
+
+}
+
# vim: ft=perl6

0 comments on commit 0f70649

Please sign in to comment.