Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,44 @@
-- <= for lists
-- compare :: [a] -> [a] -> Bool
on compare(xs, ys)
if length of xs = 0 then
true
else
if length of ys = 0 then
false
else
set {hx, txs} to uncons(xs)
set {hy, tys} to uncons(ys)
if hx = hy then
compare(txs, tys)
else
hx < hy
end if
end if
end if
end compare
-- TEST
on run
{compare([1, 2, 1, 3, 2], [1, 2, 0, 4, 4, 0, 0, 0]), ¬
compare([1, 2, 0, 4, 4, 0, 0, 0], [1, 2, 1, 3, 2])}
end run
---------------------------------------------------------------------------
-- GENERIC FUNCTION
-- uncons :: [a] -> Maybe (a, [a])
on uncons(xs)
if length of xs > 0 then
{item 1 of xs, rest of xs}
else
missing value
end if
end uncons

View file

@ -0,0 +1,32 @@
on listAComesBeforeListB(a, b)
set aLength to (count a)
set bLength to (count b)
set i to 0
repeat
set i to i + 1
if (i > bLength) then
return false
else if (i > aLength) then
return true
else
set aVal to item i of a
set bVal to item i of b
if (aVal = bVal) then
else
return (bVal > aVal)
end if
end if
end repeat
end listAComesBeforeListB
-- Test code:
set a to {}
repeat (random number 10) times
set end of a to random number 10
end repeat
set b to {}
repeat (random number 10) times
set end of b to random number 10
end repeat
return {a:a, b:b, | a < b |: listAComesBeforeListB(a, b)},

View file

@ -0,0 +1,4 @@
{a:{3, 5, 6, 5, 2, 1, 4}, b:{5, 8, 9, 2, 0, 1, 9, 0, 4, 10}, | a < b |:true}
{a:{10, 9, 5, 8, 8, 4, 3}, b:{5, 10, 8, 9, 10, 8, 7, 8}, | a < b |:false}
{a:{0, 10}, b:{0, 10}, | a < b |:false}
{a:{0, 10}, b:{0, 10, 5}, | a < b |:true}