Whoops.  I forgot it's got a left argument.
Try

    x: +/ 12000 sumq >: i. 12000  NB. !

I'd spoilt the spoiler...

Your "f" is a very nice method,  but doesn't vectorise easily.
I tried applying this more tacit version:
    fa  =:    (],[-~(]*((<.@%~ maximum &+)~)))/
    ab =.  fa  ab
for pairs of a,b

It's slightly faster,  and you can use it with a
power,   eg

    fa/ ^: number ab

This is fairly fast,  but you need to know the value for number!

You can add a counter to fa and make it conditional on 2 < {:
but performance gets poor again.

Mike

On 11/10/2011 9:55 PM, Boyko Bantchev wrote:
> On 11 October 2011 18:29, Mike Day<[email protected]>  wrote:
>> ...............
>> Run
>>     x: +/ sumq>: i. 12000     NB. very nearly a spoiler
>      Mike,
> I haven't read your solution in detail, but was curious to try it, and got
> the following:
>
>        x: +/ sumq>: i. 12000
> |domain error: sumq
> |   x:+/    sumq>:i.12000
>
>
> On ......... I wrote:
>>    f 12000
>> .................
>> ...... very slow for 12000: almost 2 min on my computer.
> I implemented the same algorithm on several other interpreted
> languages and ran it on the same machine as my J solution.
> All were significantly faster than J at 12000:
>      Rebol           – 19s,
>      CLisp           – 16s,
>      PostScript      – 9s,
>      Lua, Python     – 6.5s,
>      Ruby            – 3s,
>      Scheme (Racket) – less than 0.5s!
>
> J is often amazingly fast at whole-array (non-iterative) operations,
> but seems to be rather unfavourable to iterative (including recursive)
> ones.
> ----------------------------------------------------------------------
> 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