Nice! g=: 13 :'".,.":y' g 234 2 3 4 g [: ". [: ,. ":
-----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Dan Bron Sent: Friday, May 09, 2014 7:22 AM To: [email protected] Subject: Re: [Jprogramming] Base/antibase question 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
