diff options
| -rw-r--r-- | challenge-086/juliodcs/perl/ch-2.pl | 28 | ||||
| -rw-r--r-- | challenge-086/juliodcs/raku/ch-2.raku | 2 |
2 files changed, 8 insertions, 22 deletions
diff --git a/challenge-086/juliodcs/perl/ch-2.pl b/challenge-086/juliodcs/perl/ch-2.pl index 174e7bcc88..f1b2bfc62b 100644 --- a/challenge-086/juliodcs/perl/ch-2.pl +++ b/challenge-086/juliodcs/perl/ch-2.pl @@ -11,29 +11,15 @@ sub sudoku_solver($sudoku) { my $index = 0;
while ($index < @indexes) {
die 'No solution possible' if $index < 0;
-
+
my ($y, $x) = get_position($indexes[$index]);
-
my $guess = make_guess($sudoku, $y, $x, $backtrack);
-
- if ($guess == 0 && !$backtrack) {
- # not valid guess, We will try with next guess for same index
- $backtrack = 1;
- }
- elsif ($guess == 0 && $backtrack) {
- # not valid guess and no more guesses to test
- # We give up with this position (we decrement index)
-
- $sudoku->[$y][$x] = 0;
- $index--;
- }
- else {
- # valid guess (for now), increase index
-
- $sudoku->[$y][$x] = $guess;
- $backtrack = 0;
- $index++;
- }
+
+ # If there's a guess, We set it and increase the index
+ # if there's no guess, We clean the box and decrement the index
+ $sudoku->[$y][$x] = $guess;
+ $backtrack = !$guess;
+ $index += $guess ? 1 : -1;
}
return $sudoku;
diff --git a/challenge-086/juliodcs/raku/ch-2.raku b/challenge-086/juliodcs/raku/ch-2.raku index 44ac907224..1f3d304bf6 100644 --- a/challenge-086/juliodcs/raku/ch-2.raku +++ b/challenge-086/juliodcs/raku/ch-2.raku @@ -13,7 +13,7 @@ sub solve-sudoku(@sudoku) { # If there's a guess, We set it and increase the index
# if there's no guess, We clean the box and decrement the index
- @sudoku[$y;$x] = $guess ?? $guess !! 0;
+ @sudoku[$y;$x] = $guess;
$backtrack = not so $guess;
$index += $guess ?? 1 !! -1;
}
|
