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,43 @@
function merge(sequence left, sequence right)
sequence result
result = {}
while length(left) > 0 and length(right) > 0 do
if left[$] <= right[1] then
exit
elsif right[$] <= left[1] then
return result & right & left
elsif left[1] < right[1] then
result = append(result,left[1])
left = left[2..$]
else
result = append(result,right[1])
right = right[2..$]
end if
end while
return result & left & right
end function
function strand_sort(sequence s)
integer j
sequence result
result = {}
while length(s) > 0 do
j = length(s)
for i = 1 to length(s)-1 do
if s[i] > s[i+1] then
j = i
exit
end if
end for
result = merge(result,s[1..j])
s = s[j+1..$]
end while
return result
end function
constant s = rand(repeat(1000,10))
puts(1,"Before: ")
? s
puts(1,"After: ")
? strand_sort(s)

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(", ")}}")

View file

@ -0,0 +1,41 @@
merge_vec <- function(left, right){
result <- numeric(0)
while(length(left)>0&&length(right)>0){
if(left[1]<=right[1]){
result <- c(result, left[1])
left <- left[-1]
}
else {
result <- c(result, right[1])
right <- right[-1]
}
}
if(length(left) > 0) result <- c(result, left)
if(length(right) > 0) result <- c(result, right)
return(result)
}
strandsort <- function(v){
if(length(v)==0) stop("input vector cannot be empty")
strand <- v[1]
v <- v[-1]
sorted <- numeric(0)
while(length(v)>0){
k <- length(strand)
for(i in seq_along(v)){
if(v[i]>strand[k]){
strand <- c(strand, v[i])
v <- v[-i]
break
}
}
if(length(strand)==k){
sorted <- merge_vec(sorted, strand)
strand <- v[1]
v <- v[-1]
}
}
return(sorted)
}
strandsort(c(5,1,4,2,0,9,6,3,8,7))