Nonogram solver: Difference between revisions
m
→{{header|Julia}}
Line 1,489:
end
ycols2xrows(ycols) = [[ycols[i][j] for i in eachindex(ycols)] for j in eachindex(ycols[1])]
function hintsfromcol(rowvec, col, nrows)
Line 1,548 ⟶ 1,538:
ensurevecvec(arr::Vector{Vector{Int}}) = arr
ensurevecvec(arr::Vector{Int}) = [arr]
▲ function excludethem!(choices, otherchoices)
for i in 1:length(choices)
if length(choices[i]) > 0
Line 1,559 ⟶ 1,548:
end
end
xclude!(x, y) = (excl!(x, y); x = map(ensurevecvec, x); y = map(ensurevecvec, y); (x, y))
xlen, ylen = sum(map(length, xchoices)), sum(map(length, ychoices))
while true
if any(isempty, xchoices)
return
end
if any(isempty, ychoices)
return
Line 1,636 ⟶ 1,621:
xh, yh = map(x -> txtline2ints(strip(x)), split(xyhints, "\n"))
nonogram = NonogramPuzzle(xh, yh)
println("\nPuzzle $(pcount += 1):")
trygrids(nonogram)
foreach(x -> println(solutiontxt(x), "\n"), nonogram.solutions)
end
end
|