10&#.^:_1 ]314159 3 1 4 1 5 9 Alternatively:
ndigits=: 1 + [: <. [ ^. 1 >. ] 10 ndigits 314159 6 (10 $~ 10 ndigits 314159)#: 314159 3 1 4 1 5 9 digits=: ([ $~ ndigits) #: ] 10 digits 314159 3 1 4 1 5 9 16 digits 314159 4 12 11 2 15 On Thu, May 8, 2014 at 11:33 PM, Jon Hough <[email protected]> wrote: > I want to get the (base 10) digits of an integer as an array. > e.g. 2343 becomes an array 2 3 4 3 > My attempt is: > > tens =. 10 $ 10 tens #: 345 > result: 0 0 0 0 0 0 0 3 4 5 > I created the initial array tens as a 10 element array, and f course now I > have way too many leading zeros in my result. > How should I do this properly, returning no leading zeros, for an > arbitrary size integer? > Thanks. > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
