diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-11-23 19:51:41 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-23 19:51:41 +0000 |
| commit | bcc5415d3e812b3dd52027ee5fd72e11d31ac61d (patch) | |
| tree | 82af621620abdabcdead8fc85c980b5bbc7f1a32 | |
| parent | 4c2f829121a99cc460a35a284ea38cc52400cec8 (diff) | |
| parent | e10275ec6bebfe61451ceaeb16441c1eaaa534b8 (diff) | |
| download | perlweeklychallenge-club-bcc5415d3e812b3dd52027ee5fd72e11d31ac61d.tar.gz perlweeklychallenge-club-bcc5415d3e812b3dd52027ee5fd72e11d31ac61d.tar.bz2 perlweeklychallenge-club-bcc5415d3e812b3dd52027ee5fd72e11d31ac61d.zip | |
Merge pull request #2833 from juliodcs/juliodcs-week86
Minor changes
| -rw-r--r-- | challenge-086/juliodcs/raku/ch-2.raku | 25 |
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
|
