Problem 99 bugs?

55 views
Skip to first unread message

Jordan Thevenow-Harrison

unread,
Feb 6, 2020, 11:03:31 AM2/6/20
to 4Clojure
My solution for problem 99 gets rejected as having failed the tests, but passes them in my repl:

#(vec (map int (str (* %1 %2))))

Am I doing something wrong, or is there some incompatibility between 4clojure and this solution?

Alexey Perekhodov

unread,
Feb 7, 2020, 9:24:12 AM2/7/20
to 4Clojure
On my repl it fails also. The reason is that you try to convert symbol to int and so you get the char code of the symbol.
>(str (* 1 1))
=> "1"
>(map int "1") => (49)
>(first "1")
=> \1

Jordan Thevenow-Harrison

unread,
Feb 7, 2020, 10:06:25 AM2/7/20
to 4Clojure
Ah, I see. I was basing my evaluation in Replete, using ClojureScript, which was returning strings. I got it to work on 4Clojure with

(fn [x y] (vec (map #(. Integer parseInt (. String valueOf %)) (str (* x y)))))

Which is not elegant but works. Thanks for the heads up!

Alexey Perekhodov

unread,
Feb 7, 2020, 6:24:08 PM2/7/20
to 4Clojure
You still can make your solution look more elegant.
First, 'vec' is unnecessary -- you can provide sequence as a final result.
Then, since Clojure string is Java string, instead of (. String valueOf %) you can just write (str %).
Another way is to even avoid Java interop. Since (int \0) equals 48,
you can use 'int' conversion as in your original solution and then subtract 48.
Message has been deleted

Alexey Perekhodov

unread,
Feb 8, 2020, 2:46:41 AM2/8/20
to 4Clojure
And one more note.
Since java Integer constructur can take string as an argument you can do:
 
   >(Integer. "1")
   => 1   
Reply all
Reply to author
Forward
0 new messages