Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;; Sock Merchant problem.
- (defn match_socks
- "Given a list of integers, return the number of distinct pairs that could be made."
- [socks]
- ; Build a map of the counts for each number
- (def totals (reduce #(assoc %1 %2 (inc (%1 %2 0))) {} socks))
- ; Reduce the counts map by counting the pairs for each number
- (reduce (fn [total socks] (+ total (int (/ (last socks) 2)))) 0 totals)
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement