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

Fix code so that tests pass #1037

Open
wants to merge 2 commits 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
48 changes: 37 additions & 11 deletions src/p_p_p_pokerface.clj
Original file line number Diff line number Diff line change
@@ -1,34 +1,60 @@
(ns p-p-p-pokerface)

(defn rank [card]
nil)
(def replacements {\T 10,
\J 11,
\Q 12,
\K 13,
\A 14})
(let [[rank _] card]
(if (Character/isDigit rank)
(Integer/valueOf (str rank))
(replacements 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 (apply max (vals (frequencies (map suit hand))))))

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

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

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

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

(defn high-card? [hand]
true)

(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
(high-card? hand) 0))