Created
September 17, 2013 15:58
-
-
Save danshearmur/6596395 to your computer and use it in GitHub Desktop.
This file contains 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
(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