Skip to content

Instantly share code, notes, and snippets.

@sztamas
Last active December 22, 2015 00:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sztamas/6385704 to your computer and use it in GitHub Desktop.
Save sztamas/6385704 to your computer and use it in GitHub Desktop.
Clojure generating squares with colors.
(def FILES "abcdefgh")
(def RANKS (range 1 9))
(def squares (for [f FILES r RANKS] {:file f :rank r :name (str f r)}))
(defn opposite-color [col] (if (= col :light) :dark :light))
(defn alternate-colors [start-with]
(lazy-seq (cons start-with (alternate-colors (opposite-color start-with)))))
(def file-first-square-color (take 8 (alternate-colors :dark)))
(def square-colors
(->> (map #(take 8 (alternate-colors %)) file-first-square-color) concat flatten))
(def squares-with-colors
(map #(assoc % :color %2) squares square-colors)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment