Last active
August 29, 2015 14:06
-
-
Save alexpw/e72c998b0d0be0daaaf2 to your computer and use it in GitHub Desktop.
A possible implementation for https://groups.google.com/forum/#!topic/clojure/bouoMeogZyU
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
(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