I have the following input:
(def nums [123456789012 123456789012])
I need the following output:
[[1234 5678 9012] [1234 5678 9012]]
* note that both of these sequences contain non-string numbers ...
I thought it would be very simple by doing the following:
- Convert each record to string
- Divide each line by 4
- Convert each section back to an integer
Here is my unsuccessful attempt:
(defn split-nums [nums factor]
(map
(fn [x] (Integer/valueOf (str x)))
(partition factor (str %)))
nums))
(println (split-nums nums, 4))
When I run this, I get the following error:
Caused by: java.lang.NumberFormatException: For input string: "clojure.lang.LazySeq@4834333c"
Which tells me that I am dealing with the lazy sequence that I need to evaluate, but when I try (str (doall x)), I get the same result.
So clojure experts, where am I mistaken? Is this a good approach? BTW. I just started to learn clojure, so I'm certainly not an expert.
source
share