Solve a Hidato puzzle: Difference between revisions

m
→‎{{header|Tailspin}}: Extract raw values from tagged identifiers
(→‎{{header|Tailspin}}: Clearer types (required thanks to autotyping))
m (→‎{{header|Tailspin}}: Extract raw values from tagged identifiers)
Line 4,708:
. . . . __ 7 __ __
. . . . . . 5 __';
 
templates hidato
composer setup
Line 4,714:
@: {row: 1, col: 1, givenInput:[]};
{ board: [ <line>+ ], given: $@.givenInput -> \[i](<~={}> { n: $i, $...} !\) }
rule line: [ <cell>+ ] (<'\n '>?) (..|@: {row: $@.row::raw + 1, col: 1};)
rule cell: <open|blocked|given> (<' '>?) (@.col: $@.col::raw + 1;)
rule open: <'__'> -> 0
rule blocked: <' \.'> -> -1
Line 4,723:
$given
end setup
 
templates solve
when <~{row: <1..$@hidato.board::length>, col: <1..$@hidato.board(1)::length>}> do !VOID
Line 4,732:
def guess: $;
def back: $@hidato.board($.row; $.col);
def next: $ -> \(when <{n: <=$back>}> do $.next::raw + 1! otherwise $.next!\);
@hidato.board($.row; $.col): $.n::raw;
0..8 -> { next: $next, n: $guess.n::raw + 1, row: $guess.row::raw + $ ~/ 3 - 1, col: $guess.col::raw + $ mod 3 - 1 } -> #
@hidato.board($.row; $.col): $back;
end solve
 
@: $ -> setup;
{ next: 1, $@.given(1)... } -> solve !
end hidato
 
$input -> hidato -> '$... -> '$... -> ' $ -> \(when <=-1> do ' .' ! when <10..> do '$;' ! otherwise ' $;' !\);';
';
Anonymous user