Created
September 23, 2014 03:42
-
-
Save johnwalker/7fcf1f988cd5e6e21fd5 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
(let [day->index (into {} (map-indexed (fn [k v] [v k]) "MTWRFSN")) | |
;; So M (Monday) maps to 0, S (Saturday) maps to 5 | |
initial-state (into [] (repeat 7 0))] | |
;; Create an empty vector of seven zeroes | |
(reduce (fn [x i] (assoc x i 1)) initial-state (map day->index "MWF"))) | |
;; Map each day to an index. | |
;; (day->index \M) is 0 | |
;; so (map day->index "MWF) | |
;; is (0 2 4) | |
;; But we want [1 0 1 0 1 0 0] | |
;; So start with the seven zeroes, and add 1s for each date |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment