Skip to content

Instantly share code, notes, and snippets.

@alexpw
Last active August 29, 2015 14:06
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 alexpw/e72c998b0d0be0daaaf2 to your computer and use it in GitHub Desktop.
Save alexpw/e72c998b0d0be0daaaf2 to your computer and use it in GitHub Desktop.
(require '[clojure.string :as s])
(defn bool->int
[bool]
(if bool 1 0))
(defn single-char-days
"Translate two-char representation of certain day to one"
[days]
(-> days
(s/replace #"TH" "R")
(s/replace #"SU" "N")))
(defn flag-roster-members
"For an ordered roster of items, return a list of bool, indicating presence."
[roster members]
(map (set members) roster))
(def days-of-week [\M \T \W \R \F \S \N])
(defn flag-days-in-week
"Change string of days in week like MTTH to [1 1 0 1 0 0 0]"
[days]
(->> days
single-char-days
(flag-roster-members days-of-week)
(mapv bool->int)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment