Nonoblock: Difference between revisions

498 bytes removed ,  2 years ago
Line 1,636:
 
=={{header|Lua}}==
<lang Lua>--local nonoblockexamples = {
-- special for https://rosettacode.org/wiki/Nonoblock
 
local examples = {
{5, {2, 1}},
{5, {}},
Line 1,646 ⟶ 1,643:
{5, {2, 3}},
}
 
 
function getFreedom (n, t, tn)
local fr = n - (#t-tn) -- freedom
print ('tn', tn)
for i = tn, #t do
fr = fr - t[i]
end
return fr
end
 
 
function rep2 (n1, n2, n3)
return string.rep("0", n1) .. string.rep("1", n2) .. string.rep("0", n3)
end
 
function deep (blocks, iBlock, freedom, str)
if iBlock == #blocks then -- last
for takenFreedom = 0, freedom do
-- print ('str..string.rep("0", takenFreedom) '.. takenFreedomstring.rep("1", 'freedom 'blocks[iBlock]) .. string.rep("0", freedom - takenFreedom))
local n = freedom - takenFreedom
-- print ('n ' .. n)
local str2 = str..string.rep("0", takenFreedom) .. string.rep("1", blocks[iBlock]) .. string.rep("0", n)
print (str2)
total = total + 1
end
else
for takenFreedom = 0, freedom do
-- print ('#blocks '.. #blocks, 'iBlock ' .. iBlock)
local str2 = str..string.rep("0", takenFreedom) .. string.rep("1", blocks[iBlock]) .. "0"
deep (blocks, iBlock+1, freedom-takenFreedom, str2)
Anonymous user