diff --git a/src/p_p_p_pokerface.clj b/src/p_p_p_pokerface.clj index 5ea80094..cfffe21f 100644 --- a/src/p_p_p_pokerface.clj +++ b/src/p_p_p_pokerface.clj @@ -1,34 +1,57 @@ (ns p-p-p-pokerface) +(def replacements {\T 10, \J 11, \Q 12, \K 13, \A 14}) + (defn rank [card] - nil) + (let [[r _] card] + (if (Character/isDigit r) + (Integer/valueOf (str r)) + (replacements r)))) (defn suit [card] - nil) + (let [[_ s] card] + (str s))) (defn pair? [hand] - nil) + (< 1 (apply max (vals (frequencies (map rank hand)))))) (defn three-of-a-kind? [hand] - nil) + (< 2 (apply max (vals (frequencies (map rank hand)))))) (defn four-of-a-kind? [hand] - nil) + (< 3 (apply max (vals (frequencies (map rank hand)))))) (defn flush? [hand] - nil) + (== 5 (apply max (vals (frequencies (map suit hand)))))) (defn full-house? [hand] - nil) + (= [2 3] (sort (vals (frequencies (map rank hand)))))) (defn two-pairs? [hand] - nil) + (or + (= [1 2 2] (sort (vals (frequencies (map rank hand))))) + (four-of-a-kind? hand))) (defn straight? [hand] - nil) + (let [rank-values (sort (map rank hand)) + low-ace (sort (replace {14 1} rank-values))] + (or + (= rank-values (range (first rank-values) (+ (first rank-values) 5))) + (= low-ace (range (first low-ace) (+ (first low-ace) 5)))))) (defn straight-flush? [hand] - nil) + (and (straight? hand) (flush? hand))) (defn value [hand] - nil) + (let [high-card? (fn [x] true) + checkers #{ + [high-card? 0] + [pair? 1] + [two-pairs? 2] + [three-of-a-kind? 3] + [straight? 4] + [flush? 5] + [full-house? 6] + [four-of-a-kind? 7] + [straight-flush? 8]}] + (apply max (map second (filter (fn [x] ((first x) hand)) (map (fn [x] x) checkers))))))