Nonoblock: Difference between revisions

Line 901:
blocks [2, 3], cells 5
No solution</pre>
 
=={{header|Julia}}==
<lang julia>minsized(arr) = join(map(x->"#"^x, arr), ".")
minlen(arr) = sum(arr) + length(arr) - 1
function sequences(blockseq, numblanks)
if minlen(blockseq) == numblanks
return minsized(blockseq)
else
result = Vector{String}()
allbuthead = blockseq[2:end]
for leftspace in 0:(numblanks - minlen(blockseq))
header = "." ^ leftspace * "#" ^ blockseq[1] * "."
rightspace = numblanks - length(header)
if isempty(allbuthead)
if rightspace <= 0
push!(result, header[1:numblanks])
else
push!(result, header * "." ^ rightspace)
end
elseif minlen(allbuthead) == rightspace
push!(result, header * minsized(allbuthead))
else
for tail in sequences(allbuthead, rightspace)
push!(result, header * tail)
end
end
end
end
result isa Vector ? result : [result]
end
 
function nonoblocks(bvec, len)
println("With blocks $bvec and $len cells:")
if len < minlen(bvec)
println("No solution")
else
for seq in sequences(bvec, len)
println(seq)
end
end
end
 
nonoblocks([2, 1], 5)
nonoblocks([8], 10)
nonoblocks([2, 3, 2, 3], 15)
nonoblocks([2, 3], 5)
</lang> {{output}} <pre>
With blocks [2, 1] and 5 cells:
##.#.
##..#
.##.#
With blocks [8] and 10 cells:
########..
.########.
..########
With blocks [2, 3, 2, 3] and 15 cells:
##.###.##.###..
##.###.##..###.
##.###.##...###
##.###..##.###.
##.###..##..###
##.###...##.###
##..###.##.###.
##..###.##..###
##..###..##.###
##...###.##.###
.##.###.##.###.
.##.###.##..###
.##.###..##.###
.##..###.##.###
..##.###.##.###
With blocks [2, 3] and 5 cells:
No solution
</pre>
 
 
=={{header|Kotlin}}==
4,102

edits