Skip to content

Instantly share code, notes, and snippets.

@tolitius
Last active October 11, 2019 23:24
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 tolitius/2f2aa178de522c29fedb84249ba7f36c to your computer and use it in GitHub Desktop.
Save tolitius/2f2aa178de522c29fedb84249ba7f36c to your computer and use it in GitHub Desktop.
venn'in
=> (pprint agenda)

{:first-topic #{:justin :scott :les :valentin :andy},
 :second-topic #{:justin :scott :les :valentin :andy :gopi},
 :third-topic #{:les :valentin :andy :gopi},
 :fourth-topic #{:les :valentin :andy :gopi},
 :fifth-topic #{:beth :les :valentin :andy :gopi},
 :sixth-topic #{:beth :gopi},
 :seventh-topic #{:justin :scott :beth}}

dedupe all the voters into a single set

=> (def voters (set (mapcat identity (vals agenda))))

group topics by individual voter

=> (defn voter->topics [voter agenda]
     (let [topics (->> agenda (group-by (comp voter val)) voter (map first) set)]
     {topics #{voter}}))

bucket topics by votes

=> (defn votes-by-topics [voters agenda]
     (reduce (fn [m v]
               (merge-with (comp set concat) m (voter->topics v agenda)))
               {} voters))

great success

=> (pprint (votes-by-topics voters agenda))

{#{:seventh-topic :second-topic :first-topic} #{:justin :scott},
 #{:seventh-topic :fifth-topic :sixth-topic} #{:beth},
 #{:third-topic :second-topic :first-topic :fifth-topic :fourth-topic} #{:les :valentin :andy},
 #{:third-topic :second-topic :fifth-topic :fourth-topic :sixth-topic} #{:gopi}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment