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

solved #1038

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

solved #1038

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)

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

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

(defn rank-repeat-count [hand]
(vals (frequencies (map rank hand))))

(defn suit-repeat-count [hand]
(vals (frequencies (map suit hand))))

(defn has-n-repeats? [hand n]
(< 0 (count (filter (fn [count] (= n count)) (rank-repeat-count hand)))))

(defn pair? [hand]
nil)
(has-n-repeats? hand 2))

(defn three-of-a-kind? [hand]
nil)
(has-n-repeats? hand 3))

(defn four-of-a-kind? [hand]
nil)
(has-n-repeats? hand 4))

(defn flush? [hand]
nil)
(= 5 (apply max (suit-repeat-count hand))))

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

(defn two-pairs? [hand]
nil)
(or (four-of-a-kind? hand)
(= '(2 2) (filter (fn [repeat] (= 2 repeat)) (rank-repeat-count hand)))))

(defn sequential-ranks [rank-seq]
(range (apply min rank-seq) (+ 1( apply max rank-seq))))

(defn straight? [hand]
nil)
(let [r (sort (map rank hand))
r-generated (sequential-ranks r)
r-ace-low (sort (replace {14 1} r))
r-ace-low-generated (sequential-ranks r-ace-low)]
(or (= r r-generated)
(= r-ace-low r-ace-low-generated))))

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