Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
|
|
@ -0,0 +1,23 @@
|
|||
require "table2"
|
||||
|
||||
local function bead_sort(a)
|
||||
local res = {}
|
||||
local max = a:max()
|
||||
local trans = table.rep(max, 0)
|
||||
for a as i do
|
||||
for n = 1, i do trans[n] += 1 end
|
||||
end
|
||||
for a as _ do
|
||||
res:insert(trans:count(|n| -> n > 0))
|
||||
for n = 1, #trans do trans[n] -= 1 end
|
||||
end
|
||||
return res:reverse() -- return in ascending order
|
||||
end
|
||||
|
||||
local array = { {4, 65, 2, 31, 0, 99, 2, 83, 782, 1}, {7, 5, 2, 6, 1, 4, 2, 6, 3} }
|
||||
for array as a do
|
||||
print($"Before: \{{a:concat(", ")}}")
|
||||
local b = bead_sort(a)
|
||||
print($"After : \{{b:concat(", ")}}")
|
||||
print()
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue