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