bug-apl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-apl] Performance problem with simple program


From: Jay Foad
Subject: Re: [Bug-apl] Performance problem with simple program
Date: Tue, 6 Oct 2015 09:44:36 +0100

Your solution is inherently O(n²) because you're using ¨⍳ inside ¨⍳.
The obvious way to fix this is with +\:

(⍳N)⍪[1.5]+\{+/⍎¨⍕⍵}¨⍳N←400

The other obvious source of inefficiency is your use of ⍕ and ⍎.
Instead, how about:

(⍳N)⍪[1.5]+\+⌿10 10 10⊤⍳N←400

I don't know how to do timings in GNU APL so I can't compare this with
the previous version, but I'd hope it would be a lot faster.

Jay.

On 6 October 2015 at 06:32, Elias Mårtenson <address@hidden> wrote:
> I found the following quiz on G+, and decided to solve it with APL:
>
> https://plus.google.com/108865431001865524379/posts/FKMrYkF6h3u
>
> The solution I came up with was this:
>
>       (⍳N)⍪[1.5]{+/⍎¨⊃,/⍕¨⍳⍵}¨⍳N←400
>
> This creates a table showing the number of pages, and the sum of the digits
> for that number of pages.
>
> I was surprised that the program ran so slowly, taking almost a second to
> finish on my (pretty fast) computer.
>
> I'll follow up with profiler results, but I was wondering of anyone can come
> up with a faster solution?
>
> Regards,
> Elias



reply via email to

[Prev in Thread] Current Thread [Next in Thread]