tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
17
Task/Permutations/Lua/permutations.lua
Normal file
17
Task/Permutations/Lua/permutations.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