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

submission #1044

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: clojure
lein: lein2
script: lein2 midje :config .midje-grading-config.clj
lein: lein
script: lein midje :config .midje-grading-config.clj
jdk:
- openjdk7
notifications:
Expand Down
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)

(def face-card-values {\T 10, \J 11, \Q 12, \K 13, \A 14})

(defn rank [card]
nil)
(let [[rank-char _] card]
(if (Character/isDigit rank-char)
(Integer/valueOf (str rank-char))
(face-card-values rank-char))))

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

(defn max-with-same-rank [hand]
(apply max (vals (frequencies (map rank hand)))))

(defn max-with-same-suit [hand]
(apply max (vals (frequencies (map suit hand)))))

(defn high-card? [hand] true)

(defn pair? [hand]
nil)
(= (max-with-same-rank hand) 2))

(defn three-of-a-kind? [hand]
nil)
(= (max-with-same-rank hand) 3))

(defn four-of-a-kind? [hand]
nil)
(= (max-with-same-rank hand) 4))

(defn flush? [hand]
nil)
(= (max-with-same-suit hand) 5))

(defn full-house? [hand]
nil)
(= (sort (vals (frequencies (map rank hand)))) [2 3]))

(defn two-pairs? [hand]
nil)
(or (four-of-a-kind? hand)
(= (sort (vals (frequencies (map rank hand)))) [1 2 2])))

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

(defn straight-flush? [hand]
nil)
(and (straight? hand) (flush? hand)))

(defn value [hand]
nil)
(let [checkers #{[high-card? 0] [pair? 1] [two-pairs? 2] [three-of-a-kind? 3]
[straight? 4] [flush? 5] [full-house? 6] [four-of-a-kind? 7]
[straight-flush? 8]}
is-match? (fn [check] ((first check) hand))]
(apply max (map second (filter is-match? checkers)))
))
;(filter (fn [check] ((first check) hand)) checkers)