Created
January 1, 2012 17:41
-
-
Save weavejester/1547883 to your computer and use it in GitHub Desktop.
This file contains 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
(defn overall-rank [cards] | |
(sum (map :rank cards)) | |
(defn of-a-kind [n hand] | |
(->> (group-by :rank hand) | |
(vals) | |
(sort-by overall-rank) | |
(filter #(= n (count %))))) | |
(defn pairs [hand] | |
(of-a-kind 2 hand)) | |
(defn threes [hand] | |
(of-a-kind 3 hand)) | |
(defn independent? [xs ys] | |
(empty? (set/intersection (set xs) (set ys)))) | |
(defn full-houses [hand] | |
(sort-by overall-rank | |
(for [[t p] (threes hand) (pairs hand) :when (independent? t p)] | |
(concat t p)))) |
Somelauw
commented
Jan 1, 2012
Your independent?
method wouldn't work with overlaps:
(independent? '(5H 5C 5D) '(5C 5D))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment