Try this:

smodd1=:+/@:>:@:+:@:i.

Your tacit verb was creating forks, as can be seen with dissect:
load 'debug/dissect'
   dissect '+/1+2*i. 5'


But since the sum of the first N odd numbers is N^2
it is easiest to write
smodd=: *:


--------------------------------------------
On Tue, 5/15/18, Skip Cave <[email protected]> wrote:

 Subject: [Jprogramming] Summing odd numbers
 To: "[email protected]" <[email protected]>
 Date: Tuesday, May 15, 2018, 5:29 PM
 
 A simple Quora question wants to know the
 formula to sum the first n odd
 numbers.
 
 I can write an explicit verb:
 
 smodd =.3 :'+/1+2*i.y'
 
 smodd 5
 
 25
 
 I want to write a tacit verb:
 
 smodd1=:+/1+2*i.
 
 smodd1 5
 
 6 8 10 12 14
 
 What am I doing wrong?
 
 
 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