Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

problem 128 sandbox doesn't accept solution #200

Closed
tea-rex opened this Issue · 1 comment

2 participants

@tea-rex
(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
Owner

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!

@amcnamara amcnamara closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.