Hi Elias,

using ⍎ in an inner loop is almost certainly a mistake.

In your example ⍎ is evaluated 202287 times. That means we have
less than 5 micro-seconds for tokenising, parsing, and executing
the left argument of ⍎ and for producing it.

That does not sound that slow. In the 70s and 80's APL programmers were aware that
⍎ was inherently slow (due to the many things happening under the hood) and
did their best to avoid it.

These days I see more and more examples on the web where ⍎ is used, and
often without a real need to do so. Often APL programs look slighly more elegant
when ⍎ is used, but the speed penalty for doing so is considerable (and un-avoidable).
For the sake of APL I would hope that such examples will disappear.

/// Jürgen


On 10/06/2015 07:32 AM, Elias Mårtenson 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