[Jprogramming] Another Quora Problem
Murray Eisenberg
murray at math.umass.edu
Tue Aug 29 13:17:17 UTC 2017
The sum in question is twice the sum of the integers from 1 to 21. By the well-known formula (sometimes attributed to Gauss), the latter sum is half the product of 21 and 21 + 1, so the sum in question is
*/21+i. 2
462
> On28 Aug 2017 12:02:57 -0500,S kip Cave <skip at caveconsulting.com <mailto:skip at caveconsulting.com>> 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?
——
Murray Eisenberg murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower phone 240 246-7240 (H)
University of Massachusetts
710 North Pleasant Street
Amherst, MA 01003-9305
More information about the Programming
mailing list