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

solutions #1053

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
50 changes: 39 additions & 11 deletions src/p_p_p_pokerface.clj
Original file line number Diff line number Diff line change
@@ -1,34 +1,62 @@
(ns p-p-p-pokerface)

(defn rank [card]
nil)
(let [face-card-values {\A 14 \K 13 \Q 12 \J 11 \T 10}
card-rank-char (first card)
card-rank-is-face-card? (Character/isDigit card-rank-char)]
(if card-rank-is-face-card?
(Integer/valueOf (str card-rank-char))
(face-card-values card-rank-char ))))

(defn suit [card]
nil)
(str (second card)))

(defn pair? [hand]
nil)
(let [pair-amount 2
hand-ranks (map rank hand)
hand-rank-freq (-> hand-ranks frequencies vals)]
(.contains hand-rank-freq pair-amount)))

(defn three-of-a-kind? [hand]
nil)
(let [three-of-a-kind-amount 3
hand-ranks (map rank hand)
hand-rank-freq (-> hand-ranks frequencies vals)]
(.contains hand-rank-freq three-of-a-kind-amount)))

(defn four-of-a-kind? [hand]
nil)
(let [four-of-a-kind-amount 4
hand-ranks (map rank hand)
hand-rank-freq (-> hand-ranks frequencies vals)]
(.contains hand-rank-freq four-of-a-kind-amount)))

(defn flush? [hand]
nil)
(-> (map suit hand) frequencies vals (.contains 5)))

(defn full-house? [hand]
nil)
(and (pair? hand) (three-of-a-kind? hand)))

(defn two-pairs? [hand]
nil)
(or (> (count (filter #(= 2 %) (vals (frequencies (map rank hand))))) 1)
(.contains (vals (frequencies (map rank hand))) 4)))

(defn straight? [hand]
nil)
(let [hand-ranks-sorted (sort (map rank hand))
start-rank (first hand-ranks-sorted)
hand-ranks-sorted-low-ace (sort (replace {14 1} hand-ranks-sorted))]
(or (= hand-ranks-sorted (range start-rank (+ start-rank 5)))
(= hand-ranks-sorted-low-ace (range 1 6)))))

(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))