Skip to content

Instantly share code, notes, and snippets.

@rubysolo
Created June 13, 2013 17:28
Show Gist options
  • Save rubysolo/5775594 to your computer and use it in GitHub Desktop.
Save rubysolo/5775594 to your computer and use it in GitHub Desktop.
Kindergarden Garden
(def default-students ["Alice" "Bob" "Charlie" "David" "Eve" "Fred" "Ginny"
"Harriet" "Ileana" "Joseph" "Kincaid" "Larry"])
(def seeds { "G" :grass "C" :clover "R" :radishes "V" :violets })
(defn row-to-seeds [row-string]
(map seeds (rest (clojure.string/split row-string #""))))
(defn garden-to-rows [garden]
(clojure.string/split-lines garden))
(defn garden
([string]
(garden string default-students))
([string students]
(let [students (map #(keyword (.toLowerCase %1)) (sort students))
[front back] (map #(partition 2 %1)
(map row-to-seeds (garden-to-rows string)))]
(zipmap students (map vec
(map flatten
(partition 2 (interleave front back))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment