My favorite solution is Arie Groeneveld's pair3, but there
is a faster and leaner solution:

pair6a=: 3 : 0
 t=. ((2!y),2)$0 1+0
 t=. (1,.-.(-i.)y-2) (}:+/\(-i.)y-1)}t
 +/\t
)

pair3=:[:;<@({.,.}.)[EMAIL PROTECTED]

   (pair3 -: pair6a) 1000
1
   ts=: 6!:2 , 7!:[EMAIL PROTECTED]

   10 ts 'pair3 1000'
0.0356751 9.63603e6
   10 ts 'pair6a 1000'
0.0190992 8.39136e6

Also,   pair6a 1   gives a wrong answer.



----- Original Message -----
From: Devon McCormick <[EMAIL PROTECTED]>
Date: Friday, November 7, 2008 7:56
Subject: Re: [Jprogramming] pairs
To: Programming forum <[email protected]>

> My timings agree with the ones on your clean system: "pair3" is 
> fastest,followed by "pair2", then by "2&comb3"; all three are 
> pretty close to each
> other and are much faster than the original "pairi":
> 
>    rnk2 100&ts&>'pairi y';'pair2 y';'2&comb3 y';'pair3 
> y' [ y=. 1000
> 3  29.78 2.61     0.484 2.517e7
> 1   1.17 1.00     0.019 9.640e6
> 2   1.20 1.00     0.020 9.636e6
> 0   1.00 1.00     0.016 9.636e6
> 
> On Fri, Nov 7, 2008 at 10:28 AM, R.E. Boss 
> <[EMAIL PROTECTED]> wrote:
> 
> > On a cleaner system I get
> >
> >   rnk2 5&ts&>'pair2 y';'2&comb3 y';'pair3 y'[y=.5000
> > 1   1.04 1.00     0.737 2.834e8
> > 2   1.11 1.00     0.791 2.833e8
> > 0   1.00 1.00     0.711 2.833e8
> >
> > rnk2=: 1 7j2 5j2 10j3 8j_3 ": (,.~[: (/:@/:@:({."1) ,. }."1) (%"1
> > <./)@:(,.~
> > */"1))          
> NB. wrap around!
> >
> >
> > R.E. Boss
> >
> >
> > -----Oorspronkelijk bericht-----
> > Van: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] Namens Arie Groeneveld
> > Verzonden: vrijdag 7 november 2008 16:25
> > Aan: Programming forum
> > Onderwerp: Re: [Jprogramming] pairs
> >
> > I executed both lines, having different arguments, several times,
> > because I didn't get the same result as RE.Boss timings.
> >
> >   5j2": (%"1<./) 5&(6!:2)&>'pairi ry';'pair2 
> ry';'2&comb3 ry'[ry=.1000
> > 34.34 1.00 1.04
> >
> >
> > Devon McCormick schreef:
> > > This looks like the usual variability of timing few 
> iterations.  If you
> > try
> > > this with 100 iterations, i.e.
> > >
> > >    5j2": (%"1<./) 100&(6!:2)&>'pair2 
> ry';'pair3 ry' [ry=.25
> > >
> > > your results should be more stable.
> > >
> > > On Fri, Nov 7, 2008 at 9:38 AM, Arie Groeneveld 
> <[EMAIL PROTECTED]>> wrote:
> > >
> > >
> > >> However....
> > >>
> > >> Executing the following two lines several times (sometimes 
> I get erratic
> > >> results):
> > >>
> > >>   5j2": (%"1<./) 5&(6!:2)&>'pair2 ry';'pair3 
> ry' [ry=.25
> > >>  1.00 1.34
> > >>
> > >>   5j2": (%"1<./) 5&(6!:2)&>'pair2 ry';'pair3 
> ry' [ry=.1000
> > >>  1.02 1.00
> > >>
> > >>
> > >> Arie Groeneveld schreef:
> > >>
> > >>> Slower , but more concise
> > >>>
> > >>> pair3=:[:;<@({.,.}.)[EMAIL PROTECTED]
> > >>>
> > >>>
> > >>> Arie Groeneveld schreef:
> > >>>
> > >>>
> > >>>> pair2=:([:;],."0 _&.>[:<\.1&+)@i.@<:
> > >>>>
> > >>>>    (pair2-:pairi) 100
> > >>>> 1
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to