For equal-length arguments, you can say   repeats ;@:(#&.>) values  .  

For equal- or unequal-length arguments, you can say  repeats ;@:(#&.>)
&>/@:(>./&.:>@:,:&$ $&.> ,&<)  values  .  

There might be a cleaner way to force agreement in shape by filling
cylically; I'm just throwing this out there. 

-Dan

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Charles Turner
Sent: Thursday, March 10, 2011 8:14 AM
To: Programming forum
Subject: [Jprogramming] Newbie question about repetition...

Hi all-

Here's a little problem (not a homework assignment) that has me stumped.

Take two rank 1 arrays:

repeats =: 1 2 3 4
values =: 13 14 15 16

and want to repeat values such that the result is this rank 1 array:

13 14 14 15 15 15 16 16 16 16

I've gotten as far as:

>    times =: dyad : ', y"0 i. x' "0
>    1 2 3 4 times 13 14 15 16
> 13  0  0  0
> 14 14  0  0
> 15 15 15  0
> 16 16 16 16

But it's the wrong rank and has been filled. And it might be really awful J
as well.

Any pointers greatly appreciated. I've been reading mostly _J for C_, but
perhaps I should be looking at something else.

Next step after this is to repeat arrays of unequal length:

repeats =: 1 2 3 4
values =: 13 14

result =: 13 14 14 13 13 13 14 14 14 14

and vice versa.

Best wishes,

Charles





----------------------------------------------------------------------
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