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,29 @@
fn flipArr arr index =
(
local new = #()
for i = index to 1 by -1 do
(
append new arr[i]
)
join new (for i in (index+1) to arr.count collect arr[i])
return new
)
fn pancakeSort arr =
(
if arr.count < 2 then return arr
else
(
for i = arr.count to 1 by -1 do
(
local newArr = for n in 1 to i collect arr[n]
local oldArr = for o in (i+1) to arr.count collect arr[o]
local maxIndices = for m in 1 to (newArr.count) where (newArr[m] == amax newArr) collect m
local lastMaxIndex = maxIndices[maxIndices.count]
newArr = flipArr newArr lastMaxIndex
newArr = flipArr newArr newArr.count
arr = join newArr oldArr
)
return arr
)
)

View file

@ -0,0 +1,4 @@
a = for i in 1 to 15 collect random 0 20
#(8, 13, 2, 0, 10, 8, 1, 15, 4, 7, 6, 9, 11, 3, 5)
pancakeSort a
#(0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 10, 11, 13, 15)