Anonymous user
Solve a Hopido puzzle: Difference between revisions
m
→{{header|REXX}}: changed/added comments and whitespace, changed indentations.
SqrtNegInf (talk | contribs) m (→{{header|Perl 6}}: fixed format of initial solveboard) |
m (→{{header|REXX}}: changed/added comments and whitespace, changed indentations.) |
||
Line 674:
=={{header|REXX}}==
This REXX program is a slightly modified version of the REXX '''Hidato''' program.
<lang rexx>/*REXX program solves a Hopido puzzle, it also displays the puzzle and the solution. */
call time 'Reset' /*reset the REXX elapsed timer
parse arg xxx
xxx=translate(xxx, , "/\;:_", ',') /*also allow other
do while xxx\=''; parse var xxx r c marks ',' xxx
do while marks\='';
parse var marks x marks
if datatype(x,'N') then x=x/1 /*normalize X. */
if
if \datatype(x,'W') then call err 'illegal marker specified:' x
end /*while marks¬='' */
end /*while xxx ¬='' */
call
Nr = '0 3 0 -3 -2 2 2 -2' /*possible row for the next move. */
Nc = '3 0 -3 0 2 -2 2 -2' /* "
pMoves=words(Nr) /*the number of possible moves. */
do i=1 for pMoves; Nr.i=word(Nr, i); Nc.i=word(Nc,i); end /*
if \next(2,!r,!c) then call err 'No solution possible for this Hopido puzzle.'
say 'A solution for the Hopido exists.'; say; call
if
else say 'and took'
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
err: say; say '***error
/*──────────────────────────────────────────────────────────────────────────────────────*/
next: procedure expose @. Nr. Nc. cells pMoves; parse arg #,r,c; ##=#+1
do t=1 for pMoves /* [↓] try some moves. */
parse value r+Nr.t c+Nc.t with nr nc /*next move coördinates*/
if @.nr.nc==. then do;
if #==cells
if next(##,nr,nc)
@.nr.nc=. /*undo the above move. */
iterate /*go & try another move.*/
end
if @.nr.nc==# then do /*
if #==cells
if next(##,nr,nc)
end
end /*t*/
return 0 /*This ain't working. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
if
w=max(2,length(cells)); do r=
do c=
say _
end /*r*/
say; return</lang>
'''output''' when the input is: <br>
<pre>
. . . .
|