Advertisement
Guest User

fullhouse

a guest
Jan 1st, 2012
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defn n-of-a-kind ;untested
  2.   [n cards]
  3.   (let [ranked (vals (group-by :rank cards)),
  4.         candidates (filter #(>= (count %) n) ranked),
  5.         highest (max-by #(:rank (first c)) candidates)]
  6.     {:cards (take n highest), :remaining candidates}))
  7.  
  8. ;untested
  9. (def pair (partial n-of-a-kind 2))
  10. (def triple (partial n-of-a-kind 2))
  11.  
  12. (def fullhouse4 ;untested
  13.   [cards]
  14.   (when-let [{t :cards, remaining :remaining} (triple cards)]
  15.     (when-let [{p :cards} (pair remaining)]
  16.       (compose t p))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement