Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -0,0 +1,40 @@
local function merge(left, right)
local res = {}
while #left > 0 and #right > 0 do
if left[1] <= right[1] then
res:insert(left[1])
left:remove(1)
else
res:insert(right[1])
right:remove(1)
end
end
table.move(left, 1, #left, #res + 1, res)
table.move(right, 1, #right, #res + 1, res)
return res
end
local function strand_sort(a)
local list = a:clone()
local res = {}
while #list > 0 do
local sorted = {list[1]}
list:remove(1)
local leftover = {}
for list as item do
if sorted:back() <= item then
sorted:insert(item)
else
leftover:insert(item)
end
end
res = merge(sorted, res)
list = leftover
end
return res
end
local a = {-2, 0, -2, 5, 5, 3, -1, -3, 5, 5, 0, 2, -4, 4, 2}
print($"Unsorted: \{{a:concat(", ")}}")
a = strand_sort(a)
print($"Sorted : \{{a:concat(", ")}}")