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

Raise! #1051

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Raise! #1051

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

(defn rank [card]
nil)
(let [[rank _] card
ranks {\T 10, \J 11, \Q 12, \K 13, \A 14}]
(cond
(Character/isDigit rank) (Integer/valueOf (str rank))
:else (ranks rank))))

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

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

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

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

(defn flush? [hand]
nil)
(= [5] (vals (frequencies (map suit hand)))))

(defn full-house? [hand]
nil)
(let [freqs (vals (frequencies (map rank hand)))]
(and
(= 3 (apply max freqs))
(= 2 (apply min freqs)))))

(defn two-pairs? [hand]
nil)
(let [freqs (vals (frequencies (map rank hand)))
pair? (fn [freq] (= 2 freq))]
(= 2 (count (filter pair? freqs)))))

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


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