Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Idiomatic way to get every digit of a number

Tags:

clojure

What's the idiomatic way to get each digit of a number and put them into a sequence?

Currently I'm doing

(map #(Integer/parseInt %) (map str ((comp seq str) 123456)))

, which is somewhat ugly...

Any ideas?

like image 442
albusshin Avatar asked Mar 31 '14 20:03

albusshin


2 Answers

(for [n  (str 123456)] 
     (- (byte n) 48))
like image 189
Ankur Avatar answered Nov 15 '22 05:11

Ankur


 (map #(Character/getNumericValue %) (str 123456))
like image 28
apai Avatar answered Nov 15 '22 04:11

apai