Hi, I think they want a formula like the one to sum the first n integers (n*(n+1))/2.
For the sum of even integers up to 42 in J that would be: (*>:) -: 42 462 For the sum of even integers up to n : (*>:) <. -: i.43 0 0 2 2 6 6 12 12 20 20 30 30 42 42 56 56 72 72 90 90 110 110 132 132 156 156 182 182 210 210 240 240 272 272 306 306 342 342 380 380 420 420 462 On Mon, Aug 28, 2017 at 1:12 PM, Raul Miller <[email protected]> wrote: > 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 > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
