Bad Sorts I Wrote

Bogo sort randomly shuffles list and checks if sorted.

(defn bogo-sort
  [cards]
  (loop [L cards counter 1]
    ;; (println counter)
    (if (apply <= cards)  
      L 
      (recur (shuffle L) (+ counter 1)))))
;; 
;; end of bogo-sort
(defn bubbler-forward [xs x]
  (println xs x)
  (cond (empty? xs) [x]
    (< x (last xs)) (concat
                     (butlast xs) 
                     [x]
                     [(last xs)]) 
    ;; sticks everything together if x is less than the last of xs
    :else (concat xs [x])))
;; else it just x at the end of xs

(defn bubbler-back [xs x]
  (println xs x)
  (cond (empty? xs) [x]
    (> x (first xs)) (concat
                      [(first xs)]
                      [x]
                      (rest xs)) 
    ;; sticks everything together if x is less than the last of xs
    :else (concat [x] xs)))
(defn cocktail-sort
  [L]
  (println "L" L)
  (let [xs (reduce bubbler-back [] (reverse (reduce bubbler-forward [] L)))]
    (if (apply <= xs) xs
      (recur xs)))) ;; end of cocktail sort, my only good sorting algorithm
;; https://eddmann.com/posts/bubble-sort-in-clojure/
(defn bogobogosort
  [L]
  (loop [N 0 l L q (bogobogosort (butlast l)) la (last l)]
    (if (> l (max q)) (concat q la)
      (recur (+ N 1) (shuffle (concat q la)) (bogobogosort (butlast l)) (last l))))) ;; bugged but funny, even more inefficient than bogo-sort
;; https://www.dangermouse.net/esoteric/bogobogosort.html 

Miracle sort waits 10 seconds, then checks if alpha particles changed a bit and miraculously sorted the list.

(defn miracle-sort
  [L]
  (Thread/sleep 10000)
  (println L)
  (if (apply <= L) L
    (recur L)))

Intelligent design sort assumes that the list is already in order because an intelligent being has transcended humanity and sorted the list in a way that transcends the thought process of normal humans found a much more intelligent way to sort such list.

(defn intelligent-design-sort
  [L]
  L)
;; https://www.dangermouse.net/esoteric/intelligentdesignsort.html

Sleep sort is an esoteric sorting function that makes a number pause for how long the value is, and then shouting out the value. This makes the numbers shout out smallest to largest, making it a viable sorting algorithm

(defn blarg [N]
  (Thread/sleep (* 100 N))
  (println N))

(defn make-thread 
  [N]
  (let [thread (Thread. #(blarg N))]
    (.start thread)
    thread))

(defn sleep-sort 
  [L]
  (map make-thread L))

;(doseq [thread (sleep-sort (shuffle (range 10)))] (.join thread))

Stalin sort an esoteric sorting algorithm that just kicks out values that aren't in order

(defn stalin [xs x]
  (println xs x)
  (cond (empty? xs) [x]
    (< x (last xs)) (concat xs) 
    :else (concat xs [x])))

(defn stalin-sort
  [L]
  (println "L" L)
  (reduce stalin [] L))
(defn abs 
  [n]
  (if (< n 0) 
    (* n -1)
    n))

(defn max-gap
  [L]
  (if (< (count L) 2) 0)
  (loop [N 0 l (sort L)]
    (cond (= 1 (count l)) N
      (< N (abs (- (first l) (second l)))) (recur (abs (- (first l) (second l))) (rest l))
      :else (recur N (rest l)))))