Data update

This commit is contained in:
Ingy döt Net 2025-06-11 20:16:52 -04:00
parent 72eb4943cb
commit 4d5544505c
2347 changed files with 62432 additions and 16731 deletions

View file

@ -0,0 +1,68 @@
module Strand_sort{
function strand_sort(aa as array) {
function mergelist(sa, sb) {
flush ' empty current stack
variant v, g
integer L=3
while len(sa) and len(sb)
if L=1 else stack sa {read v}
if L=2 else stack sb {read g}
if v<g then
data v: L=2
else
data g:L=1
end if
end while
' dump stacks to current stack
If L=1 then data v
if L=2 then data g
data !sa, !sb
' return the current stack as-is
=[]
}
function strand(&a) {
flush
variant v, g
if len(a)<1 then =a:exit
stack a {read v }: data v
i=1
L=0
while i <= len(a)
if i<>L then
stack a {
shift i ' get i_th item as top
over ' copy one
read g ' read in a variant
shiftback i ' send back to i
}
L=i
end if
if g > v then
stack a {
shift i
drop
}
data g
v = g
else
i++
end if
end while
=[]
}
a=stack(aa)
out = strand(&a)
while len(a)
out = mergelist(out, strand(&a))
end while
=array(out)
}
m = (1, 6, 3, 2, 1, 7, 5, 3)
Print m
Print strand_sort(m)
m = ("aa", "cc", "bb", "a1")
Print m
Print strand_sort(m)
}
Strand_sort