fork download
  1. (use 'clojure.string)
  2. (defn f[n](let[s(str n)i(map #(-(int %)48)(str(Math/abs n)))](+(apply +(cons(*(first i)(if(< n 0)-1 1))(rest i)))n(count s))))
  3. (defn g[n](let[s(str(Math/abs n))c(count (str n))d(str(if(< n 0)"0""")(join"+"s))i(map #(-(int %)48)s)j(cons(*(first i)(if(< n 0)-1 1))(rest i))s(apply + j)](str n\+ c"+("d")="(+ s c n))))
  4. (println (f 99))
  5. (println (f -123))
  6. (println (f 0))
  7. (println (f 1))
  8. (println (g 99))
  9. (println (g -123))
  10. (println (g 0))
  11. (println (g 1))
Success #stdin #stdout #stderr 2s 335488KB
stdin
Standard input is empty
stdout
119
-115
1
3
99+2+(9+9)=119
-123+4+(01+2+3)=-115
0+1+(0)=1
1+1+(1)=3
stderr
WARNING: reverse already refers to: #'clojure.core/reverse in namespace: user, being replaced by: #'clojure.string/reverse
WARNING: replace already refers to: #'clojure.core/replace in namespace: user, being replaced by: #'clojure.string/replace