up=: 3 :'UP=:y' NB. temp result cache
xx=: (<"1) 15 3 $ 12 | 45 ?. 200
yy=: (<"1) 10 4 $ 12 | 40 ?. 60

   up I.@:-. each (<"1)(,. >{:each xx) i."1 >{.each yy
+---+-+-+-++-+---+-+++-+-++-----++
|5 9|2|6|8||2|5 9|2|||8|0||1 4 7||
+---+-+-+-++-+---+-+++-+-++-----++

(,. (>(#) each UP) # xx) ,. (> ( 0<# )  each , > ({&yy) each UP) # , > ({&yy) 
each UP

+------+---------+
|2 6 7 |7 7 0 5  |
+------+---------+
|2 6 7 |7 1 3 3  |
+------+---------+
|7 6 5 |5 11 8 8 |
+------+---------+
|8 6 0 |0 0 9 3  |
+------+---------+
|4 2 4 |4 9 5 8  |
+------+---------+
|8 10 5|5 11 8 8 |
+------+---------+
|6 11 7|7 7 0 5  |
+------+---------+
|6 11 7|7 1 3 3  |
+------+---------+
|7 10 5|5 11 8 8 |
+------+---------+
|9 2 4 |4 9 5 8  |
+------+---------+
|11 8 6|6 11 1 10|
+------+---------+
|0 5 10|10 8 8 1 |
+------+---------+
|0 5 10|10 11 4 3|
+------+---------+
|0 5 10|10 4 3 7 |
+------+---------+

version that drops leading item from yy,
(,. (>(#) each UP) # xx) ,. (> ( 0<# )  each , > ({&yy) each UP) # }. each , > 
({&yy) each UP


----- Original Message ----
From: Yuvaraj Athur Raghuvir <[EMAIL PROTECTED]>
To: Programming forum <[email protected]>
Sent: Sunday, October 22, 2006 9:26:05 PM
Subject: Re: [Jprogramming] Re: Using position-match array to generate result - 
eliminate the for loop

Pacal, the solution proposed has a problem as it does not scale right.
Looks like there is an assumption on the shape somewhere.

Let me call the rajoin you have proposed as rajoin1.

   rajoin1 =: 4 : '(x ,. ]) (({: |: x) i.~ ({. |: y)) { {: |: y'

Now, try this:
   x =. 15 3 $ 12 | 45 ?. 200
   y =. 10 4 $ 12 | 40 ?. 60

   x rajoin1 y
|index error: rajoin1
|   (x,.])(({:|:x)i.~({.|:y))    {{:|:y

However,
   x rajoin y
+----+--+-------+
|2 6 |7 |7 0 5  |
+----+--+-------+
|2 6 |7 |1 3 3  |
+----+--+-------+
|7 6 |5 |11 8 8 |
+----+--+-------+
|8 6 |0 |0 9 3  |
+----+--+-------+
|4 2 |4 |9 5 8  |
+----+--+-------+
|8 10|5 |11 8 8 |
+----+--+-------+
|6 11|7 |7 0 5  |
+----+--+-------+
|6 11|7 |1 3 3  |
+----+--+-------+
|7 10|5 |11 8 8 |
+----+--+-------+
|9 2 |4 |9 5 8  |
+----+--+-------+
|11 8|6 |11 1 10|
+----+--+-------+
|0 5 |10|8 8 1  |
+----+--+-------+
|0 5 |10|11 4 3 |
+----+--+-------+
|0 5 |10|4 3 7  |
+----+--+-------+

]x
 2  6  7
 7  6  5
 8  6  0
 4  2  4
 9  4  9
 8 10  5
 6 11  7
 7 10  5
 4 11  3
 2  1  9
 9  2  4
11  8  6
11  0  1
 0  5 10
 5 10 11
 ]y
 6 11 1 10
10  8 8  1
 5 11 8  8
 2  0 1  5
10 11 4  3
 7  7 0  5
 0  0 9  3
10  4 3  7
 4  9 5  8
 7  1 3  3


On 10/23/06, Pascal Jasmin <[EMAIL PROTECTED]> wrote:
> this will work if y is sorted (easily fixed if not) and indexed continuously 
> (left column) from 1 to #y
>
> (x ,. ]) (1 -~ {: |: x) { {: |: y
>
> otherwise, we need to make an indexlookup verb (just i.~) as the left 
> argument for { .
>
> (x ,. ]) (({: |: x) i.~ ({. |: y)) { {: |: y
> rajoin =: 4 : '(x ,. ]) (({: |: x) i.~ ({. |: y)) { {: |: y'
>
----------------------------------------------------------------------
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