Created
July 21, 2017 23:25
-
-
Save spirinvladimir/797e5ebf5a2939627fffe078d26089fc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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