Solve a Hidato puzzle: Difference between revisions

Line 1,906:
 
=={{header|Julia}}==
This solution utilizes a moduleHidato whichpuzzle issolver looselymodule based on the Python version, andwhich is also used for the Hopido taskand knight move tasks.
<lang julia>module Hidato
 
Line 1,937:
end
 
function hidatosolve(board, maxmoves, movematrix, fixed, row, col, sought, next)
if sought > maxmoves
return true
Line 1,943:
return false
end
backnum = board[row, col] == sought ? sought : 0
if board[row, col] == sought
backnum = sought
next += 1
end
board[row, col] = sought # try board with this cell set to next number
for move in movematrix
i, j = row + move[1], col + move[2]
if (0 < i <= size(board)[1]) && (0 < j <= size(board)[2]) &&
hidatosolve(board, maxmoves, movematrix, fixed, i, j, sought + 1, next)
return true
end
Line 1,983 ⟶ 1,979:
board, maxmoves, fixed, starts = hidatoconfigure(hidat)
printboard(board)
hidatosolve(board, maxmoves, kingmoves, fixed, starts[1][1], starts[1][2], 1, 1)
printboard(board)
</lang>{{output}}<pre>
4,102

edits