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,11 @@
(defun pancake-sort (seq)
"A destructive version of Pancake Sort that works with either lists or arrays of numbers."
(defun flip (lst index)
(setf (subseq lst 0 index) (reverse (subseq lst 0 index))))
(loop with lst = (coerce seq 'list)
for i from (length lst) downto 2
for index = (position (apply #'max (subseq lst 0 i)) lst)
do (unless (= index 0)
(flip lst (1+ index)))
(flip lst i)
finally (return (coerce lst (type-of seq)))))

View file

@ -0,0 +1,6 @@
CL-USER> (pancake-sort '(6 7 8 9 2 5 3 4 1)) ;list
(1 2 3 4 5 6 7 8 9)
CL-USER> (pancake-sort #(6 7 8 9 2 5 3 4 1)) ;array
#(1 2 3 4 5 6 7 8 9)
CL-USER> (pancake-sort #(6.5 7.5 8 9 2 5 3 4 1.0)) ;array with integer and floating point values
#(1.0 2 3 4 5 6.5 7.5 8 9)