Skip to content

Instantly share code, notes, and snippets.

@danshearmur
Created September 17, 2013 15:58
Show Gist options
  • Save danshearmur/6596395 to your computer and use it in GitHub Desktop.
Save danshearmur/6596395 to your computer and use it in GitHub Desktop.
(defn get-chars-at [seq count]
(reduce (fn [accum next]
(let [next-char (get next count)
char (if-not (nil? next-char) next-char " ")]
(str accum char)))
"" seq))
(defn max-count [seq]
(reduce (fn max-count [last line]
(let [c (count line)]
(if (< last c) c last)))
0 seq))
(defn transpose [str]
(let [lines (clojure.string/split-lines str)
max-length (max-count lines)]
(clojure.string/join "\n"
(for [i (range max-length)]
(get-chars-at lines i)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment