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

Exercises for p-p-p-pokerface #1050

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

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

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

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

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

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

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

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

(defn two-pairs? [hand]
nil)
(let [freqs (vals (frequencies (map rank hand)))]
(or (and
(= (apply max freqs) 2)
(= (count freqs) 3))
(four-of-a-kind? hand))))

(defn straight? [hand]
nil)
(let [ranks (sort (map rank hand))
is_straight_vals (fn [v] (= v (range (apply min v) (+ (apply min v) 5))))]
(or
(is_straight_vals ranks)
(is_straight_vals (sort (replace {14 1} ranks))))))

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