Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 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