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

from ke #1028

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

from ke #1028

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

(defn rank [card]
nil)
(let [c (first card)]
(if (Character/isDigit c)
(Integer/valueOf (str c))
(get {\T 10, \J 11, \Q 12, \K 13, \A 14} c))))

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


(defn pair? [hand]
nil)
(->> (map rank hand)
frequencies
vals
(some #(= % 2))
boolean))

(defn three-of-a-kind? [hand]
nil)
(->> (map rank hand)
frequencies
vals
(some #(= % 3))
boolean))


(defn four-of-a-kind? [hand]
nil)
(->> (map rank hand)
frequencies
vals
(some #(= % 4))
boolean))


(defn flush? [hand]
nil)
(= 1
(->> (map suit hand)
set
count)))

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

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

(defn straight? [hand]
nil)
(let [sorted-ranks (sort (map rank hand))
min-rank (first sorted-ranks)]
(or (= sorted-ranks
(range min-rank (+ min-rank 5)))
(= sorted-ranks
[2 3 4 5 14]))))

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