Excerpt from thread to make this post self contained:
NB.===========
A=: 0,~ ([EMAIL PROTECTED])(-<./)+/\<:?.1e3#3
B=: 0,~?.2#~<:#A
example=:4 :0 NB. a example b
c=.1+Iy=.I.y
while.1 e. s=.c >&({&x) Iy do.
c=.c+s
end.
c
)
nng0=:([>:@+{(1 i.~>:)>:@[}.])"0 _
NB.===========
Based on the fact that
+/B
4698
#~.B#A
35
further improvement (in such cases) is possible:
ts'A example B'
0.24420391 149824
ts'(I.B) nng0 A'
0.11849653 216000
rpl=:] - (-/ , 0:)@[ {~ [EMAIL PROTECTED] i. ]
nng1=: <@](],:&;(]([>:@+ 1 i.~>:@[}.])"0 _ [<: ({~{.))&.>) #</[EMAIL PROTECTED]
ts'(I.B) rpl~ B nng1 A'
0.018779726 255616
(A example B)-:(I.B) rpl~ B nng1 A
1
Relative performance:
rnk 5 ts&>'A example B';'(I.B) nng0 A';'(I.B) rpl~ B nng1 A'
2 8.48 1.00
1 4.36 1.43
0 1.00 1.70
R.E. Boss
-----Oorspronkelijk bericht-----
Van: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Namens Raul Miller
Verzonden: maandag 20 oktober 2008 21:21
Aan: Programming forum
Onderwerp: Re: [Jprogramming] Re: next not greater
On Mon, Oct 20, 2008 at 2:40 PM, R.E. Boss <[EMAIL PROTECTED]> wrote:
> BTW, a few years ago we had a similar problem:
> http://www.jsoftware.com/pipermail/general/2005-January/019976.html
Thank you, I had forgotten about that particular problem.
I should also note that this problem seems to be somewhat related to
the problem of finding intersections between a line and an arbitrary
curve. (Except that, for example, in this case we can test all
possibilities.)
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm