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,13 @@
(defun span (predicate list)
(let ((tail (member-if-not predicate list)))
(values (ldiff list tail) tail)))
(defun less-than (x)
(lambda (y) (< y x)))
(defun insert (list elt)
(multiple-value-bind (left right) (span (less-than elt) list)
(append left (list elt) right)))
(defun insertion-sort (list)
(reduce #'insert list :initial-value nil))

View file

@ -0,0 +1,18 @@
(defun insertion-sort (sequence &optional (predicate #'<))
(if (cdr sequence)
(insert (car sequence) ;; insert the current item into
(insertion-sort (cdr sequence) ;; the already-sorted
predicate) ;; remainder of the list
predicate)
sequence)) ; a list of one element is already sorted
(defun insert (item sequence predicate)
(cond ((null sequence) (list item))
((funcall (complement predicate) ;; if the first element of the list
(car sequence) ;; isn't better than the item,
item) ;; cons the item onto
(cons item sequence)) ;; the front of the list
(t (cons (car sequence) ;; otherwise cons the first element onto the front of
(insert item ;; the list of the item sorted with the rest of the list
(cdr sequence)
predicate)))))