Slightly slower is sprl_b which was inspired by 'involute'.
lr 'sprl_b'
$ /:@~.@,@(i.@>[EMAIL PROTECTED]:@<./ ([EMAIL PROTECTED] +"1 (*"0 _ {:)) [:
((,~ {.)@] ,:~ 0: +/\@,
[)&>/ <: <@(, -)@|[EMAIL PROTECTED]"1 (_1: , {:) ,:~ {: , 1:)
5 ts 'sprl_b 1000 2000'
0.18509537 58721280
5 ts 'involute2 1000 2000'
0.14915697 25183296
R.E. Boss
-----Oorspronkelijk bericht-----
Van: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Namens Jose Mario Quintana
Verzonden: maandag 4 december 2006 16:17
Aan: 'Programming forum'
Onderwerp: RE: [Jprogramming] spiral order
I noticed, coming back from a short vacation, that I did not paste the final
version of involute2; here it is:
lr'involute2'
([ $ /:@(+/\@(,@(] {. |:@((1 0 + [EMAIL PROTECTED]@|.)@[)) # +:@] $ (, -)@(1 ,
{:@[))))
<./
The relative performance is not affected:
st'involute0 400 600'
6302784 0.0354399791
st'involute1 400 600'
4195328 0.0379573382
st'involute2 400 600'
3155008 0.034524779
> [EMAIL PROTECTED] On Behalf Of Jose Mario Quintana
> lr'lr'
> 5!:5@<
>
>
> Eesuk's explicit generalization of a classic solution:
>
> lr'involute0'
> 3 : 0
> t=.<./'M N'=.y
> p=.,t{.|:(>:i.-N),:i.-M
> d=.(+:t)$(,-)1,N
> y$/:+/\p#d
> )
>
> Eesuk's tacit version:
>
> lr'involute1'
> $ /:@(+/\)@(,@(<./ {. |:@(1 0 + [EMAIL PROTECTED]@|.)) # +:@<./ $ (, -)@(1 ,
> {:))
>
> A slight variation:
>
> lr'involute2'
> ([ $ /:@(+/\@(,@(] {. |:@((1 0 + [EMAIL PROTECTED]@|.)@[)) # +:@] $ (, -)@(1
> , {:@[))))
> {.
>
> lr'st'
> 7!:2 , 6!:2
>
> st'involute0 400 600'
> 6302784 0.025494581
> st'involute1 400 600'
> 4195328 0.0252504159
> st'involute2 400 600'
> 3155008 0.0255353683
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm