Solve a Hidato puzzle: Difference between revisions
Content added Content deleted
m (→{{header|Tailspin}}: use new integer division operator) |
m (→{{header|Tailspin}}: syntax update) |
||
Line 4,048: | Line 4,048: | ||
composer setup |
composer setup |
||
@: {row: 1, col: 1, given:[]}; |
@: {row: 1, col: 1, given:[]}; |
||
{ board: [ <line>+ ], given: $@.given -> [i](<{}> { n: $i, $...} !) } |
{ board: [ <line>+ ], given: $@.given -> \[i](<{}> { n: $i, $...} !\) } |
||
rule line: [ <cell>+ ] (<'\n '>?) (..|@: {row: $@.row + 1, col: 1};) |
rule line: [ <cell>+ ] (<'\n '>?) (..|@: {row: $@.row + 1, col: 1};) |
||
rule cell: <open|blocked|given> (<' '>?) (@.col: $@.col + 1;) |
rule cell: <open|blocked|given> (<' '>?) (@.col: $@.col + 1;) |
||
Line 4,061: | Line 4,061: | ||
templates solve |
templates solve |
||
<~{row: <1..$@hidato.board::length>, col: <1..$@hidato.board(1)::length>}> !VOID |
<~{row: <1..$@hidato.board::length>, col: <1..$@hidato.board(1)::length>}> !VOID |
||
<{ n: <$@hidato.given(-1).n>, row: <$@hidato.given(-1).row>, col: <$@hidato.given(-1).col> }> $@hidato.board ! |
<{ n: <=$@hidato.given(-1).n>, row: <=$@hidato.given(-1).row>, col: <=$@hidato.given(-1).col> }> $@hidato.board ! |
||
<?($@hidato.board($.row; $.col) <~0|$.n>)> !VOID |
<?($@hidato.board($.row; $.col) <~=0|=$.n>)> !VOID |
||
<?($@hidato.board($.row; $.col) <0>)?($@hidato.given($.next) <$.n>)> !VOID |
<?($@hidato.board($.row; $.col) <=0>)?($@hidato.given($.next) <=$.n>)> !VOID |
||
<> |
<> |
||
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: $ -> \(<{n: <=$back>}> $.next + 1! <> $.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,077: | Line 4,077: | ||
end hidato |
end hidato |
||
$input -> hidato -> '$... -> '$... -> ' $ -> (<-1> ' .' ! <10..> '$;' ! <> ' $;' !);'; |
$input -> hidato -> '$... -> '$... -> ' $ -> \(<=-1> ' .' ! <10..> '$;' ! <> ' $;' !\);'; |
||
'; |
'; |
||
' ->!OUT::write |
' ->!OUT::write |