f0=: 4 : '+/x=/y'
f1=: 4 : 0
y1=. y#~ s=. ~:y
i=. /:y1,x
b=. i<#y1
(y1 i. y){(#;._1 b) (b#i)}y1
)
f1a=: 4 : 0 NB. same as f1 if y has unique elements
i=. /:y,x
b=. i<#y
(#;._1 b) (b#i)}y
)
The value of f1a comes the insight that it offers.
It is only slightly more efficient than f1.
x=: 1e4 [EMAIL PROTECTED] 100
y=: 1000 [EMAIL PROTECTED] 105
y1=: ~.y
x (f0 -: f1) y
1
x (f0 -: f1) y1
1
x (f0 -: f1) y1
1
x (f0 -: f1a) y1
1
ts=: 6!:2 , 7!:[EMAIL PROTECTED]
ts 'x f0 y'
0.0712959 1.67861e7
ts 'x f1 y'
0.000639746 135872
ts 'x f0 y1'
0.00733752 2.10074e6
ts 'x f1 y1'
0.000615162 134144
ts 'x f1a y1'
0.000595886 133376
One more thing: if you are dealing with floating point
numbers you have to be aware that /: and thus f1 and f1a
are not tolerant but = and thus f0 is tolerant. That is,
you have to be aware what is meant by "matching"
----- Original Message -----
From: Alex Rufon <[EMAIL PROTECTED]>
Date: Thursday, September 18, 2008 7:19
Subject: [Jprogramming] Verb Sequence or Ranking problem?
To: Programming forum <[email protected]>
> Hi.
>
> I'm still at verb sequences and I have a question which I am guessing
> that is more of a rank solution.
>
> I have the following values:
> [a=: 1 1 2 2 3 5 5 5
> 1 1 2 2 3 5 5 5
> [b=: 3 4 5 5 3 1 2
> 3 4 5 5 3 1 2
>
> What I wanted to do was count the number of matching numbers in
> a that
> are in b. So potentially, my result should be:
> 1 0 3 3 1 2 2
>
> Which if I append to the b noun, I should get:
> 3 1
> 4 0
> 5 3
> 5 3
> 3 1
> 1 2
> 2 2
>
> I can actually solve this by using a for loop but that's what
> I'm trying
> to avoid. So I reasoned that I can count by each number like so:
> #I. a e. 5
> 3
> #I. a e. 4
> 0
>
> Using verb sequencing, I can recode this as:
> a [EMAIL PROTECTED]@e. 5
> 3
> a [EMAIL PROTECTED]@e. 4
> 0
>
> So far so good. Now this is where I hit a snag, I tried to use
> the code
> above against b and I get the following:
> a [EMAIL PROTECTED]@e. each b
> |length error
> | a [EMAIL PROTECTED]@e.each b
> a [EMAIL PROTECTED]@e. ,.b
> 0
> a [EMAIL PROTECTED]@e. every b
> |length error
> | a [EMAIL PROTECTED]@e.every b
>
> a [EMAIL PROTECTED]@e. "_ b
> 8
> a [EMAIL PROTECTED]@e. "0 b
> |length error
> | a [EMAIL PROTECTED]@e."0 b
> a [EMAIL PROTECTED]@e. "1 b
> 8
> a [EMAIL PROTECTED]@e.@> (< every b)
> |length error
> | a [EMAIL PROTECTED]@e.@>(<every b)
> a [EMAIL PROTECTED]@[EMAIL PROTECTED] (< every b)
> |syntax error
> | [EMAIL PROTECTED]@[EMAIL PROTECTED](<every b)
>
> So as you can see, I still have a long way to go. :(
>
> r/Alex
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm