Jump to content

Find the missing permutation: Difference between revisions

(→‎{{header|Lua}}: shortened)
Line 1,108:
=={{header|Lua}}==
Using the popular Penlight extension module - https://luarocks.org/modules/steved/penlight
<lang Lua>local permute, tablex = require("pl.permute"), require("pl.tablex")
 
function notIn (t, str)
for k, v in pairs(t) do
if v == str then return false end
end
return true
end
 
local permList, pStr = {
"ABCD", "CABD", "ACDB", "DACB", "BCDA", "ACBD", "ADCB", "CDAB",
Line 1,122 ⟶ 1,114:
"DCBA", "BACD", "BADC", "BDAC", "CBDA", "DBCA", "DCAB"
}
for _, perm in pairs(permute.tableiter({"A","B","C","D"})) do
pStr = table.concat(perm)
if notInnot tablex.find(permList, pStr) then print(pStr) end
end</lang>
{{out}}
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.