Thanks to all for the help. I have done the following tests and so far
zsban2 comes out as the best solution.


   raul1        =: ] {~ ~: >./\@:* [EMAIL PROTECTED]@]
   zsban1       =: (~:(#{~[:<:+/[EMAIL PROTECTED])])
   zsban2       =: (~:(#;.1##)]) NB. Mike also?
   oleg1        =:  [^:(0=])/\
   brand1       =: ( ((] {~ <:@:(I.@:=))`(I.@:=)`])}  ) ^:_

   y =: 0 0 1 0 2 0 0 3 0 0 0 4 0 0 0 0

   0 raul1 y
0 0 1 1 2 2 2 3 3 3 3 4 4 4 4 4
   0 zsban1 y
4 4 1 1 2 2 2 3 3 3 3 4 4 4 4 4
   0 zsban2 y
1 1 2 2 2 3 3 3 3 4 4 4 4 4
   oleg1 y
0 0 1 1 2 2 2 3 3 3 3 4 4 4 4 4
   0 brand1 y
4 4 1 1 2 2 2 3 3 3 3 4 4 4 4 4

   NB. time
   10000 (6!:2) '0 raul1 y'
4.19281e_6
   10000 (6!:2) '0 zsban1 y'
5.02911e_6
   10000 (6!:2) '0 zsban2 y'
3.78488e_6
   10000 (6!:2) 'oleg1 y'
0.000147781
   10000 (6!:2) '0 brand1 y'
2.25551e_5

   NB. space
    (7!:2) '0 raul1 y'
1280
    (7!:2) '0 zsban1 y'
1216
    (7!:2) '0 zsban2 y'
1280
    (7!:2) 'oleg1 y'
2432
    (7!:2) '0 brand1 y'
5824

   NB. Summary
   NB. zsban2 is fastest and fills leading zeroes with
   NB. the first non-zero which is desirable.
   NB. It also does well in terms of memory used.

On Thu, Oct 30, 2008 at 6:07 AM, Oleg Kobchenko <[EMAIL PROTECTED]> wrote:
>> From: Matthew Brand <[EMAIL PROTECTED]>
>
>>
>> Hi All,
>>
>> Is there a tacit way to copy forward the number which occurs before
>> the first zero in any sequence of zeroes into the positions of those
>> zeroes?
>>
>> E.g. Is there a tacit f which does this:
>>    0 f 1 0 2 3 4 5 0 0 0 4 3 2 4
>> 1 1 2 3 4 5 5 5 5 4 3 2 4
>
> Not strictly dyadic, but here is a simple tacit idea:
>
>   [^:(0=])/\  1 0 2 3 4 5 0 0 0 4 3 2 4
> 1 1 2 3 4 5 5 5 5 4 3 2 4
>
>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to