Skip to content

Instantly share code, notes, and snippets.

@spirinvladimir
Created July 21, 2017 23:25
Show Gist options
  • Save spirinvladimir/797e5ebf5a2939627fffe078d26089fc to your computer and use it in GitHub Desktop.
Save spirinvladimir/797e5ebf5a2939627fffe078d26089fc to your computer and use it in GitHub Desktop.
(def s (Integer/parseInt (read-line)))
(def stdin (read-line))
(def nums (vec (map #(Integer/parseInt %) (clojure.string/split stdin #" "))))
(defn insertOne [position collection size]
(let [v (nth collection position)]
(loop [a collection
p (dec position)]
(if (= p -1)
a
(let [prev (nth a p)
incP (inc p)]
(if (< v prev)
(recur
(assoc (assoc a p (nth a incP)) incP prev)
(dec p))
a))))))
(def res (loop [n 1
a nums
res []]
(if (< n s)
(let [sortIteration (insertOne n a s)]
(recur
(inc n)
sortIteration
(vec (conj res (clojure.string/join " " sortIteration)))))
res)))
(doall (map println res))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment