f=: (+!) i. 10
digits=: 10&#.^:_1
spcl=: = +/"1@({&f)@digits

   rank ';([: spcl&.> 10&(<....@^.) </.])d';';(10&(<....@^.)
<@(spcl)/.])d'[d=:i.1e6
+----+-----+----+----+
|rank|tm*sz|time|size|
+----+-----+----+----+
| 0  |1.00 |1.00|1.00|
+----+-----+----+----+
| 1  |1.29 |1.06|1.22|
+----+-----+----+----+

   d#~".&> ';([: (spcl)&.> 10&(<....@^.) </.])d';';(10&(<....@^.) <@(spcl)/.])d'
85837 408297
85837 408297


R.E. Boss


> -----Oorspronkelijk bericht-----
> Van: [email protected] [mailto:programming-
> [email protected]] Namens Marshall Lochbaum
> Verzonden: maandag 30 augustus 2010 4:36
> Aan: 'Programming forum'
> Onderwerp: Re: [Jprogramming] Splitting an integer into its digits
> 
> 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
> 


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to