Guest User

fullhouse

a guest
Jan 1st, 2012
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defn fullhouse2
  2.   ([cards]
  3.      (let [ranked (group-by :rank cards),
  4.            counted (group-by (comp count second) ranked),
  5.            {pairs 2, triples 3} (into {} (for [[c r] counted] {c (into {} r)}))]
  6.        (when (>= (+ (count pairs) (count triples)) 2)
  7.          (let  [[r triple] (apply max-key first triples)
  8.                 paircands (merge pairs (dissoc triples r))
  9.                 [_ pair] (apply max-key first paircands)]
  10.            (into triple (take 2 pair)))))))
Advertisement
Add Comment
Please, Sign In to add comment