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

problem 128 sandbox doesn't accept solution #200

Closed
tea-rex opened this issue Dec 31, 2011 · 1 comment
Closed

problem 128 sandbox doesn't accept solution #200

tea-rex opened this issue Dec 31, 2011 · 1 comment

Comments

@tea-rex
Copy link

tea-rex commented Dec 31, 2011

(def regonize-card
(fn [card]
 (letfn [
  (to-suit [c]
   (case c
    \D :diamond
    \H :heart
    \C :club
    \S :spade))
  (to-val [c]
   (let [value (-> c (int) (- 50))]
    (if (< value 8) value
     (case c
      \T 8 \J 9 \Q 10 \K 11 \A 12)))) ]
  (-> {}
   (assoc :suit (to-suit (first card)))
   (assoc :rank (to-val (second card)))
  )))
)

(recognize-card "DQ")
(recognize-card "H5")
(recognize-card "CA")

4clojure responds with: java.security.PrivilegedActionException: java.lang.ClassCastException: clojure.lang.PersistentVector cannot be cast to clojure.lang.MapEntry (NO_SOURCE_FILE:0)

This code works just fine at the REPL

@amcnamara
Copy link
Member

The sandbox doesn't allow the use of case but you're basically doing a hash-map lookup, so you can rework it like so:

(fn [card]
 (letfn [(to-suit [c]
           (get {\D :diamond
                 \H :heart
                 \C :club
                 \S :spade} c))
         (to-val [c]
           (let [value (-> c (int) (- 50))]
             (if (< value 8) value
               (get {\T 8 \J 9 \Q 10 \K 11 \A 12} c))))]
    {:suit (to-suit (first card))
     :rank (to-val (second card))}))

Hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants