Created
June 13, 2013 17:28
-
-
Save rubysolo/5775594 to your computer and use it in GitHub Desktop.
Kindergarden Garden
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
(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