(ns bubble-sort (:gen-class)) (defn- bubble [ys x] (if-let [y (peek ys)] (if (> y x) (conj (pop ys) x y) (conj ys x)) [x])) (defn bubble-sort [xs] (let [ys (reduce bubble  xs)] (if (= xs ys) xs (recur ys)))) (defn- convert-to-int-array [string] (->> (clojure.string/split string #", " ) (map #(Integer/parseInt %)))) (defn- convert-to-string [int-array] (clojure.string/join ", " int-array)) (defn- print-bubble-sort [string] (println (convert-to-string (bubble-sort (convert-to-int-array string))))) (defn- is-valid-input [args] (and (not= (count args) 0) (not= (first args) "") (> (count (convert-to-int-array (first args))) 1) )) (defn- print-error  (println "Usage: please provide a list of at least two integers to sort in the format \"1, 2, 3, 4, 5\"")) (defn main [args] (try (if (is-valid-input args) (print-bubble-sort (first args)) (print-error)) (catch Exception e (print-error)))) (main *command-line-args*)
If you see anything you’d like to change or update, please consider contributing.
Note: The solution shown above is the current solution in the Sample Programs repository as of Oct 19 2019 23:52:25. The solution was first committed on Oct 02 2019 16:17:26. As a result, documentation below may be outdated.
No ‘How to Implement the Solution’ section available. Please consider contributing.
No ‘How to Run the Solution’ section available. Please consider contributing.