Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ppp solved #1061

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 43 additions & 11 deletions src/p_p_p_pokerface.clj
Original file line number Diff line number Diff line change
@@ -1,34 +1,66 @@
(ns p-p-p-pokerface)

(def replacements {\T 10, \J 11 \Q 12 \K 13 \A 14})

(defn rank [card]
nil)
(let [[fst _] card]
(if (Character/isDigit fst)
(Integer/valueOf (str fst))
(get replacements fst))))

(defn suit [card]
nil)
(let [[_ snd] card]
(str snd)))

(defn pair? [hand]
nil)
(let [ranks (map rank hand)
freq (vals (frequencies ranks))]
(>= (apply max freq) 2)))

(defn three-of-a-kind? [hand]
nil)
(let [ranks (map rank hand)
freq (vals (frequencies ranks))]
(>= (apply max freq) 3)))

(defn four-of-a-kind? [hand]
nil)
(let [ranks (map rank hand)
freq (vals (frequencies ranks))]
(>= (apply max freq) 4)))

(defn flush? [hand]
nil)
(let [suits (map suit hand)]
(apply = suits)))

(defn full-house? [hand]
nil)
(let [ranks (map rank hand)
freq (vals (frequencies ranks))]
(every? #(or (= % 2) (= % 3)) freq)))

(defn two-pairs? [hand]
nil)
(let [ranks (map rank hand)
freq (vals (frequencies ranks))]
(= '(1 2 2) (sort freq))))

(defn straight? [hand]
nil)
(let [ranks (map rank hand)
sorted-ranks (sort ranks)
inv-sorted-ranks (sort (replace {14 1} ranks))]
(or (= (take 5 (iterate inc (first sorted-ranks))) sorted-ranks)
(= (take 5 (iterate inc (first inv-sorted-ranks))) inv-sorted-ranks))))

(defn straight-flush? [hand]
nil)
(let [ranks (map rank hand)]
(and (straight? hand) (flush? hand))))

(defn high-card? [hand]
true)

(defn value [hand]
nil)
(let [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 [[bool _]] bool)
(map (fn [[f score]] [(f hand) score]) checkers))))
))