Data update

This commit is contained in:
Ingy döt Net 2023-12-16 21:33:55 -08:00
parent 35bcdeebf8
commit 74c69a0df6
2427 changed files with 31826 additions and 3468 deletions

View file

@ -0,0 +1,42 @@
global array
dim array = {10, 1, 2, -6, 3}
lb = array[?,]-1 : ub = array[?]-1
print "unsort ";
for i = lb to ub
print rjust(array[i], 4);
next i
call Bogosort(array) # ordenar el array
print chr(10); " sort ";
for i = lb to ub
print rjust(array[i], 4);
next i
end
subroutine shuffle(array)
n = array[?] : m = array[?]*2
for k = 1 to m
i = int(Rand*n)
j = int(Rand*n)
tmp = array[i] #swap lb(i), lb(j)
array[i] = array[j]
array[j] = tmp
next k
end subroutine
function inorder(array)
n = array[?]
for i = 0 to n-2
if array[i] > array[i+1] then return false
next i
return true
end function
subroutine Bogosort(array)
while not inorder(array)
call shuffle(array)
end while
end subroutine

View file

@ -1,6 +1,6 @@
(function bogo-sort order list
(return-when (empty? list) [])
(if (.. order list)
(return-unless (1 list) [])
(if (... order list)
list
(recur order (shuffle list))))

View file

@ -1,3 +1,13 @@
dim a(5)
a (0) = 10: a (1) = 1: a (2) = 2: a (3) = -6: a (4) = 3
Bogosort(a())
for i = 0 to arraysize(a(),1) - 1
print a(i), " ";
next i
end
sub shuffle(a())
n = arraysize(a(),1)
m = arraysize(a(),1)*2
@ -15,7 +25,7 @@ sub inorder(a())
n = arraysize(a(),1)
for i = 0 to n-2
if a(i) > a(i+1) then return false : fi
if a(i) > a(i+1) return false
next i
return true
end sub
@ -25,13 +35,3 @@ sub Bogosort(a())
shuffle(a())
wend
end sub
dim a(5)
a (0) = 10: a (1) = 1: a (2) = 2: a (3) = -6: a (4) = 3
Bogosort(a())
for i = 0 to arraysize(a(),1) - 1
print a(i), " ";
next i
end