aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjuliodcs <julio.dcs@gmail.com>2020-11-23 19:44:06 +0100
committerjuliodcs <julio.dcs@gmail.com>2020-11-23 19:44:06 +0100
commite10275ec6bebfe61451ceaeb16441c1eaaa534b8 (patch)
tree89313bc844554f25360e483f12f9550f02e21fc9
parent965ebcdfe343395ec7800d5dfe924ad4385b10b5 (diff)
downloadperlweeklychallenge-club-e10275ec6bebfe61451ceaeb16441c1eaaa534b8.tar.gz
perlweeklychallenge-club-e10275ec6bebfe61451ceaeb16441c1eaaa534b8.tar.bz2
perlweeklychallenge-club-e10275ec6bebfe61451ceaeb16441c1eaaa534b8.zip
Minor changes
-rw-r--r--challenge-086/juliodcs/raku/ch-2.raku25
1 files changed, 7 insertions, 18 deletions
diff --git a/challenge-086/juliodcs/raku/ch-2.raku b/challenge-086/juliodcs/raku/ch-2.raku
index 194eab6a9e..44ac907224 100644
--- a/challenge-086/juliodcs/raku/ch-2.raku
+++ b/challenge-086/juliodcs/raku/ch-2.raku
@@ -1,9 +1,9 @@
#! /usr/bin/raku
sub solve-sudoku(@sudoku) {
- my @indexes := get-indexes(@sudoku);
+ my @indexes := get-indexes @sudoku;
- my $backtrack = 0;
+ my $backtrack = False;
my $index = 0;
while $index < @indexes.elems {
die 'No solution possible' if $index < 0;
@@ -11,22 +11,11 @@ sub solve-sudoku(@sudoku) {
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 ?? $guess !! 0;
+ $backtrack = not so $guess;
+ $index += $guess ?? 1 !! -1;
}
@sudoku