Skip to content

Instantly share code, notes, and snippets.

@weavejester
Created January 1, 2012 17:41
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 weavejester/1547883 to your computer and use it in GitHub Desktop.
Save weavejester/1547883 to your computer and use it in GitHub Desktop.
(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
Copy link

Somelauw commented Jan 1, 2012

(defn independant? [xs ys]
  (not= (set xs) (set ys))

@weavejester
Copy link
Author

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