diff --git a/src/p_p_p_pokerface.clj b/src/p_p_p_pokerface.clj index 5ea80094..4b2e815e 100644 --- a/src/p_p_p_pokerface.clj +++ b/src/p_p_p_pokerface.clj @@ -1,34 +1,74 @@ (ns p-p-p-pokerface) (defn rank [card] - nil) + (let [c (first card)] + (if (Character/isDigit c) + (Integer/valueOf (str c)) + (get {\T 10, \J 11, \Q 12, \K 13, \A 14} c)))) (defn suit [card] - nil) + (str (second card))) + (defn pair? [hand] - nil) +(->> (map rank hand) +frequencies +vals +(some #(= % 2)) +boolean)) (defn three-of-a-kind? [hand] - nil) + (->> (map rank hand) + frequencies + vals + (some #(= % 3)) + boolean)) + (defn four-of-a-kind? [hand] - nil) + (->> (map rank hand) + frequencies + vals + (some #(= % 4)) + boolean)) + (defn flush? [hand] - nil) + (= 1 + (->> (map suit hand) + set + count))) (defn full-house? [hand] - nil) + (and (pair? hand) (three-of-a-kind? hand))) (defn two-pairs? [hand] - nil) + (->> (map rank hand) + frequencies + vals + (filter #(= % 2)) + count + (#(= % 2)))) (defn straight? [hand] - nil) + (let [sorted-ranks (sort (map rank hand)) + min-rank (first sorted-ranks)] + (or (= sorted-ranks + (range min-rank (+ min-rank 5))) + (= sorted-ranks + [2 3 4 5 14])))) (defn straight-flush? [hand] - nil) + (and (straight? hand) + (flush? hand))) (defn value [hand] - nil) + (cond (straight-flush? hand) 8 + (four-of-a-kind? hand) 7 + (full-house? hand) 6 + (flush? hand) 5 + (straight? hand) 4 + (three-of-a-kind? hand) 3 + (two-pairs? hand) 2 + (pair? hand) 1 + :else 0))