Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
17
Task/Permutations/Lua/permutations-1.lua
Normal file
17
Task/Permutations/Lua/permutations-1.lua
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
local function permutation(a, n, cb)
|
||||
if n == 0 then
|
||||
cb(a)
|
||||
else
|
||||
for i = 1, n do
|
||||
a[i], a[n] = a[n], a[i]
|
||||
permutation(a, n - 1, cb)
|
||||
a[i], a[n] = a[n], a[i]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--Usage
|
||||
local function callback(a)
|
||||
print('{'..table.concat(a, ', ')..'}')
|
||||
end
|
||||
permutation({1,2,3}, 3, callback)
|
||||
Loading…
Add table
Add a link
Reference in a new issue