Find the missing permutation: Difference between revisions

Content added Content deleted
(→‎{{header|Lua}}: shortened)
Line 1,108: Line 1,108:
=={{header|Lua}}==
=={{header|Lua}}==
Using the popular Penlight extension module - https://luarocks.org/modules/steved/penlight
Using the popular Penlight extension module - https://luarocks.org/modules/steved/penlight
<lang Lua>local permute = require("pl.permute")
<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 = {
local permList, pStr = {
"ABCD", "CABD", "ACDB", "DACB", "BCDA", "ACBD", "ADCB", "CDAB",
"ABCD", "CABD", "ACDB", "DACB", "BCDA", "ACBD", "ADCB", "CDAB",
Line 1,122: Line 1,114:
"DCBA", "BACD", "BADC", "BDAC", "CBDA", "DBCA", "DCAB"
"DCBA", "BACD", "BADC", "BDAC", "CBDA", "DBCA", "DCAB"
}
}
for _, perm in pairs(permute.table({"A","B","C","D"})) do
for perm in permute.iter({"A","B","C","D"}) do
pStr = table.concat(perm)
pStr = table.concat(perm)
if notIn(permList, pStr) then print(pStr) end
if not tablex.find(permList, pStr) then print(pStr) end
end</lang>
end</lang>
{{out}}
{{out}}