The limiting factor here isn't the speed of the part that removes the
initial 0s, it's the fact that you are doing the whole thing rank 1. This
way, (+/"1@({&f)) has to reinitialize for every row, which is SLOW.
Essentially, this approach is the same as (stuff)@digits"0 in that the
output from digits for each scalar is rank 1, so then applying a rank 1 verb
to it is the same but with more overhead.The only way to really get rid of the padding problem is to do it for only the numbers which have a certain number of digits, and loop over all the digits less than your maximum. Marshall -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of gary ng Sent: Sunday, August 29, 2010 9:26 PM To: Programming forum Subject: Re: [Jprogramming] Splitting an integer into its digits On Sun, Aug 29, 2010 at 5:36 PM, Marshall Lochbaum <[email protected]> wrote: > Oh, or > }.~ [: i.&1 ~:&0 > That should be really fast. > Not sure if I am doing the right thing or there is something else(I am a newbie in J): 6!:2 ' +/"1@({&f)@(}.~ [: i.&1 ~:&0)"1@(digits)i.1000000' 2.90104 6!:2 ' +/"1@({&f)@(#~[:>&0+/\)"1(digits)i.1000000' 2.75834 | 6!:2 ' +/"1@({&f)@(#~[:+./\~:&0)"1@(digits)i.1000000' 2.85498 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
