Skip to content

Instantly share code, notes, and snippets.

@johnwalker
Created September 23, 2014 03:42
Show Gist options
  • Save johnwalker/7fcf1f988cd5e6e21fd5 to your computer and use it in GitHub Desktop.
Save johnwalker/7fcf1f988cd5e6e21fd5 to your computer and use it in GitHub Desktop.
(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