aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjuliodcs <julio.dcs@gmail.com>2020-11-26 19:23:17 +0100
committerjuliodcs <julio.dcs@gmail.com>2020-11-26 19:23:17 +0100
commit1394f0691dd45f342843e5f507a1d25f47a974c0 (patch)
tree8d4e66450e9127113a5c0c9efa39afc03d72b323
parente10275ec6bebfe61451ceaeb16441c1eaaa534b8 (diff)
downloadperlweeklychallenge-club-1394f0691dd45f342843e5f507a1d25f47a974c0.tar.gz
perlweeklychallenge-club-1394f0691dd45f342843e5f507a1d25f47a974c0.tar.bz2
perlweeklychallenge-club-1394f0691dd45f342843e5f507a1d25f47a974c0.zip
small simplification
-rw-r--r--challenge-086/juliodcs/perl/ch-2.pl28
-rw-r--r--challenge-086/juliodcs/raku/ch-2.raku2
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;
}