Well... the simplest J implementation for that problem would be:

   462
462

But there are other ways of getting that result:

   +/(* 0 = 2&|)1+i.42
462
   +/(* 0 = 2&|)i.43
462
   +/2*i.>:-:42
462
   +/2*1+i.21
462
   +/2*i.22
462

and... so on...

I suppose a part of the question is: what is acceptable, to the
audience, to do outside the computer implementation? (Which, in turn,
can lead to forbidding all languages except the one preferred by a
specific person, among other things.)

Thanks,

-- 
Raul

On Mon, Aug 28, 2017 at 1:02 PM, Skip Cave <[email protected]> wrote:
> A simple problem posted on Quora:
>
> What is the sum of all the even numbers from 2 to 42?
>
> My J solution:
>    a=:>:i.42
>   +/(-.2|a)#a
> 462
>
> I'm sure this can be done in a single line using a hook or fork.
> but I'm not clear enough with the train rules to put this all together
> on a single line.
> Any suggestions?
>
>
>
>
>
> Skip Cave
> Cave Consulting LLC
> ----------------------------------------------------------------------
> 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