Solve a Hidato puzzle: Difference between revisions

Content added Content deleted
(→‎{{header|Raku}}: Fix up internal links)
m (→‎{{header|Tailspin}}: syntax update)
Line 4,062: Line 4,062:


templates solve
templates solve
<~{row: <1..$@hidato.board::length>, col: <1..$@hidato.board(1)::length>}> !VOID
when <~{row: <1..$@hidato.board::length>, col: <1..$@hidato.board(1)::length>}> do !VOID
<{ n: <=$@hidato.given(-1).n>, row: <=$@hidato.given(-1).row>, col: <=$@hidato.given(-1).col> }> $@hidato.board !
when <{ n: <=$@hidato.given(last).n>, row: <=$@hidato.given(last).row>, col: <=$@hidato.given(last).col> }> do $@hidato.board !
<?($@hidato.board($.row; $.col) <~=0|=$.n>)> !VOID
when <?($@hidato.board($.row; $.col) <~=0|=$.n>)> do !VOID
<?($@hidato.board($.row; $.col) <=0>)?($@hidato.given($.next) <=$.n>)> !VOID
when <?($@hidato.board($.row; $.col) <=0>)?($@hidato.given($.next) <=$.n>)> do !VOID
<>
otherwise
def guess: $;
def guess: $;
def back: $@hidato.board($.row; $.col);
def back: $@hidato.board($.row; $.col);
def next: $ -> \(<{n: <=$back>}> $.next + 1! <> $.next!\);
def next: $ -> \(when <{n: <=$back>}> do $.next + 1! otherwise $.next!\);
@hidato.board($.row; $.col): $.n;
@hidato.board($.row; $.col): $.n;
0..8 -> { next: $next, n: $guess.n + 1, row: $guess.row + $ ~/ 3 - 1, col: $guess.col + $ mod 3 - 1 } -> #
0..8 -> { next: $next, n: $guess.n + 1, row: $guess.row + $ ~/ 3 - 1, col: $guess.col + $ mod 3 - 1 } -> #
Line 4,079: Line 4,079:
end hidato
end hidato


$input -> hidato -> '$... -> '$... -> ' $ -> \(<=-1> ' .' ! <10..> '$;' ! <> ' $;' !\);';
$input -> hidato -> '$... -> '$... -> ' $ -> \(when <=-1> do ' .' ! when <10..> do '$;' ! otherwise ' $;' !\);';
';
';
' ->!OUT::write
' ->!OUT::write