Jump to content

Find the missing permutation: Difference between revisions

Added Lua version
No edit summary
(Added Lua version)
Line 1,105:
,/p2@&~(p2:{x@m@&n=(#?:)'m:!n#n:#x}[*p]) _lin p
</lang>
 
=={{header|Lua}}==
Using the popular Penlight extension module - https://luarocks.org/modules/steved/penlight
<lang Lua>local permute = require("pl.permute")
 
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",
"DABC", "BCAD", "CADB", "CDBA", "CBAD", "ABDC", "ADBC", "BDCA",
"DCBA", "BACD", "BADC", "BDAC", "CBDA", "DBCA", "DCAB"
}
for _, perm in pairs(permute.table({"A","B","C","D"})) do
pStr = table.concat(perm)
if notIn(permList, pStr) then print(pStr) end
endM</lang>
{{out}}
<pre>DBAC</pre>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.