Skip to content

Commit

Permalink
method add-number (untested)
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz committed Sep 11, 2010
1 parent 878fead commit de392cd
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/Sudoku.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
Expand Down

0 comments on commit de392cd

Please sign in to comment.