"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."

One can always ask the tacit translator (if worst come to worst one would
get an explicit answer back).

   13 : '+/(-.2|a)#a [ a=.>:i.42'
[: ([: +/ ([: -. 2 | ]) # ]) (1+i.42)"_

   ([: ([: +/ ([: -. 2 | ]) # ]) (1+i.42)"_) _
462

Its answer can be improved but at least it shows one way to do it,

   ([: +/ ([: -. 2 | ]) # ]) (1+i.42)
462

etc.

The tacit translator was my faithful teacher a long time ago and I still
use it occasionally, nowadays to understand non-tacit code.

I hope it helps.


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