From e10275ec6bebfe61451ceaeb16441c1eaaa534b8 Mon Sep 17 00:00:00 2001 From: juliodcs Date: Mon, 23 Nov 2020 19:44:06 +0100 Subject: Minor changes --- challenge-086/juliodcs/raku/ch-2.raku | 25 +++++++------------------ 1 file 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 -- cgit