See also http://www.jsoftware.com/help/release/digits10.htm
"."0@": 314159 3 1 4 1 5 9 ,.&.": is indeed cute and worthy of inclusion in the list of Unders http://www.jsoftware.com/jwiki/Essays/Under and of special code if I'd thought of it. On Fri, May 9, 2014 at 4:21 AM, Dan Bron <[email protected]> wrote: > Also worth noting: > > ,.&.": 345 > 3 4 5 > > I stole this cute phrasing from Björn, but the basic premise is: convert > the integer to string representation (":), break it up into its component > characters, which correspond to its individual digits (,.), and then > convert those characters back into integers (&.). > > Plenty of other ways to phrase it, some of which will permit > higher-dimensional input (,.&.":"0 works fine on any array, but verbs which > process arrays in toto typically have better performance than low-rank > verbs which have to break up large arguments first). > > -Dan > > > On May 9, 2014, at 2:40 AM, Roger Hui <[email protected]> wrote: > > > > 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 > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
