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

p-p-p-pokerface solution #1058

Open
wants to merge 2 commits 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
64 changes: 53 additions & 11 deletions src/p_p_p_pokerface.clj
Original file line number Diff line number Diff line change
@@ -1,34 +1,76 @@
(ns p-p-p-pokerface)

(defn rank [card]
nil)
(let [[fst _] card]
(cond
(= "2" (str fst)) 2
(= "3" (str fst)) 3
(= "4" (str fst)) 4
(= "5" (str fst)) 5
(= "6" (str fst)) 6
(= "7" (str fst)) 7
(= "8" (str fst)) 8
(= "9" (str fst)) 9
(= "T" (str fst)) 10
(= "J" (str fst)) 11
(= "Q" (str fst)) 12
(= "K" (str fst)) 13
(= "A" (str fst)) 14
:else 0)))

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

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

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

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

(defn flush? [hand]
nil)
(let [freqVals (vals (frequencies (map suit hand)))]
(= (apply max freqVals) 5)))

(defn full-house? [hand]
nil)
(let [[fst sec] (vec (sort (vals (frequencies (map rank hand)))))]
(and (= fst 2) (= sec 3))))

(defn two-pairs? [hand]
nil)
(let [[fst sec] (vec (reverse (sort (vals (frequencies (map rank hand))))))]
(or (and (= fst 2) (= sec 2)) (four-of-a-kind? hand))))


(defn straight? [hand]
nil)
(let [hand-distinct-ranks (distinct (map rank hand))
hand-distinct-ranks-ace-1 (replace {14 1} hand-distinct-ranks)
min-ace-14 (apply min hand-distinct-ranks)
max-ace-14 (apply max hand-distinct-ranks)
min-ace-1 (apply min hand-distinct-ranks-ace-1)
max-ace-1 (apply max hand-distinct-ranks-ace-1)
ace-14-range (range (- max-ace-14 min-ace-14))
ace-1-range (range (- max-ace-1 min-ace-1))]
(cond
(not= (count hand-distinct-ranks) 5) false
:else (or (= (count ace-1-range) 4) (= (count ace-14-range) 4)))))

(defn straight-flush? [hand]
nil)
(and (straight? hand) (flush? hand)))

(defn value [hand]
nil)
(cond
(and (not (two-pairs? hand)) (pair? hand)) 1
(and (not (four-of-a-kind? hand)) (two-pairs? hand)) 2
(and (not (full-house? hand)) (three-of-a-kind? hand)) 3
(and (straight? hand) (not (straight-flush? hand))) 4
(and (flush? hand) (not (straight-flush? hand))) 5
(full-house? hand) 6
(four-of-a-kind? hand) 7
(straight-flush? hand) 8
:else 0))