Permalink
Browse files

method add-number (untested)

  • Loading branch information...
1 parent 878fead commit de392cd7b895eac640f125369b354364dc48c2b9 @moritz committed Sep 11, 2010
Showing with 13 additions and 0 deletions.
  1. +13 −0 lib/Sudoku.pm
View
@@ -24,6 +24,19 @@ class Sudoku {
@!rows.map({ .map({ $_ == 0 ?? '.' !! $_ }).join ~ "\n" }).join;
}
+ method add-number($n, :$x, :$y) {
+ given @!rows[$y][$x] {
+ if $_ && $_ !== $n {
+ die "Trying to set ($x, $y) to $n, but it is already set (to $_)";
+ }
+ }
+ @!constraints[$y][$y] = [0 xx $!size];
+ for ^$!size {
+ @!constraints[$y][$_][$n - 1] = 0;
+ @!constraints[$_][$x][$n - 1] = 0;
+ }
+ }
+
method init() {
for ^$!size X ^$!size -> $x, $y {
@!constraints[$y][$x] = [ True xx $!size ];

0 comments on commit de392cd

Please sign in to comment.