Skip to content
Browse files

start with trivial case solving

  • Loading branch information...
1 parent ea69f14 commit 4f800ed29623114bb3c4320783183515537a2c66 @moritz committed Sep 5, 2010
Showing with 23 additions and 3 deletions.
  1. +20 −1 lib/Nonogram.pm
  2. +3 −2 test.pl
View
21 lib/Nonogram.pm
@@ -49,13 +49,32 @@ method Str {
@result.push: '0';
}
@result.push: '|';
- @result.push: @.field-rows[$row-num].join();
+ @result.push: @!field-rows[$row-num].join();
@result.push: "|\n";
}
sep-line();
@result.join;
}
+method solve() {
+ # trivial cases first
+ $.solve-zero();
+}
+
+method solve-zero() {
+ for @.colspec.kv -> $k, $v {
+ if $v.elems == 0 {
+ for @!field-rows {
+ .[$k] = ' ';
+ }
+ }
+ }
+ for @.rowspec.kv -> $idx, $row {
+ if $row.elems == 0 {
+ @!field-rows.[$idx][*] = ' ' xx *;
+ }
+ }
+}
# vim: ft=perl6
View
5 test.pl
@@ -8,5 +8,6 @@
rowspec => ([], [4], [6], [2, 2], [2, 2], [6], [4], [2], [2], [2], []),
);
-print $n;
-
+say $n;
+$n.solve();
+say $n;

0 comments on commit 4f800ed

Please sign in to comment.
Something went wrong with that request. Please try again.