Created
December 3, 2014 00:20
-
-
Save philipschwarz/c7e3be1ac97e482d04bf to your computer and use it in GitHub Desktop.
First stab at Clojure print-diamond
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
(defn print-diamond [letter] | |
(let [alphabet "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
position-of (fn [letter] (inc (- (int letter) (int \A)))) | |
number-of-letters (position-of letter) | |
dashes (fn [n] (repeat n \-)) | |
fixed-text-for (fn [letter] (concat (dashes (dec (position-of letter))) (list letter))) | |
template (map fixed-text-for (take number-of-letters alphabet)) | |
pad-with-trailing-dashes (fn [index line] (concat line (dashes (dec (- number-of-letters index))))) | |
top-right-quadrant (map-indexed pad-with-trailing-dashes template) | |
top-left-quadrant (map reverse (map rest (take number-of-letters top-right-quadrant))) | |
top-half (map concat top-left-quadrant top-right-quadrant) | |
diamond (concat top-half (drop 1 (reverse top-half)))] | |
(doseq [line (map #(apply str %) diamond)] | |
(println line)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment