all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
|
|
@ -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)))))
|
||||
|
|
@ -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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue