Solve a Hidato puzzle: Difference between revisions
m
→{{header|Julia}}
Line 1,908:
{{trans|Python}}
<lang julia>function hidatoconfigure(str)
lines = map(x -> x * " ", split(str, "\n"))
board = fill(-1, (nrows, div(ncols, 3)))
presets = Vector{Int}()
startpos
for i in 1:nrows, j in 1:div(ncols, 3)
if (ch = lines[i][3 * (j-1) + 2]) == '_'
board[i, j] = 0
elseif ch == '.'
Line 1,941 ⟶ 1,932:
if sought > fixed[end]
return true
elseif (board[row, col] != 0 && board[row, col] != sought) || (board[row, col] == 0 && fixed[next] == sought)
return false
end
Line 1,953 ⟶ 1,943:
maxrow, maxcol = size(board)
for i in max(row - 1, 1):min(row + 1, maxrow), j in max(col -1, 1):min(col + 1, maxcol)
if !(i == row && j == col) && hidatosolve(board, fixed, i, j, sought +1, next)
return true
end
Line 1,965 ⟶ 1,953:
function printboard(board)
d = Dict(-1 => " ", 0 => "__ ", -2 => "\n")
println(join([d[i] for i in hcat(board, fill(-2, size(board)[1]))'], ""))
end
|