function permuteCases(word)
local word = string.lower(word)
local padding = "%0" .. #word .. "d"
tex.print("\\begin{ttfamily}")
for decimal=0, 2^(#word)-1 do
local binary = ""
while decimal > 0 do
local remainder = decimal % 2
binary = tostring(remainder) .. binary
decimal = math.floor(decimal / 2)
end
binary = string.format(padding, binary == "" and "0" or binary)
local perm = ""
for j=1, #word do
if string.sub(binary, j, j) == "0" then
perm = perm .. string.sub(word, j, j)
else
perm = perm .. string.upper(string.sub(word, j, j))
end
end
tex.print(perm .. "\\quad")
if (decimal+1) % #word == 0 then
tex.print("\\newline")
end
end
tex.print("\\end{ttfamily}")
end
말씀대로 고치니 table도 필요없군요.
function permuteCases(word)
local word = string.lower(word)
local padding = "%0" .. #word .. "d"
tex.print("\\begin{ttfamily}")
for decimal=0, 2^(#word)-1 do
local binary = ""
while decimal > 0 do
local remainder = decimal % 2
binary = tostring(remainder) .. binary
decimal = math.floor(decimal / 2)
end
binary = string.format(padding, binary == "" and "0" or binary)
local perm = ""
for j=1, #word do
if string.sub(binary, j, j) == "0" then
perm = perm .. string.sub(word, j, j)
else
perm = perm .. string.upper(string.sub(word, j, j))
end
end
tex.print(perm .. "\\quad")
if (decimal+1) % #word == 0 then
tex.print("\\newline")
end
end
tex.print("\\end{ttfamily}")
end