I wrote a simple program to sum the digits of a number in Clojure for learning purpose. Not very complex (I hope) so not adding any explanation. I am a beginner in Clojure so please don't mind pointing out even the most obvious mistakes.
NOTE: It recursively calculates the sum of digits in the result until a single digit result is obtained. For example, given "4312", 1 is returned (4312 -> 10 -> 1).
(defn sum-once [x]
(reduce +
(map
#(Integer/parseInt (str %))
(seq (char-array x)))))
(defn sum-digits [x]
(let [y (sum-once x)]
(if (< y 10) y
(sum-digits (str y)))))
(sum-digits "4312")
gives 1 \$\endgroup\$edit
you'll seelang-clj
as the language tag. \$\endgroup\$