Permutations: Difference between revisions
Content added Content deleted
(Added demo code second D version) |
(Lua) |
||
Line 1,499: | Line 1,499: | ||
[3,2,1] |
[3,2,1] |
||
yes</lang> |
yes</lang> |
||
=={{header|Lua}}== |
|||
<lang lua> |
|||
local function permutation(a, n) |
|||
if n == 0 then |
|||
print('{'..table.concat(a, ', ')..'}') |
|||
else |
|||
for i = 1, n do |
|||
a[i], a[n] = a[n], a[i] |
|||
permutation(a, n - 1) |
|||
a[i], a[n] = a[n], a[i] |
|||
end |
|||
end |
|||
end |
|||
permutation({1,2,3}, 3) |
|||
-- {2, 3, 1} |
|||
-- {3, 2, 1} |
|||
-- {3, 1, 2} |
|||
-- {1, 3, 2} |
|||
-- {2, 1, 3} |
|||
-- {1, 2, 3} |
|||
</lang> |
|||
=={{header|Mathematica}}== |
=={{header|Mathematica}}== |