Linda offers:
f=: 13 :'+/"1(>:/~i.y)*(y#x)+/i.y' NB. (msgsbelow)

My best f ,  with an [: for Linda's sake:
   f =: ([:+/\ (+i.))
   4 f 7
4 9 15 22 30 39 49

HOWEVER, although Skip initially asked for a way to render
4, (4+5), (4+5+6),  ... recursively, we may consider that
the (i+1)th term may be defined recursively as
   t(i+1) = ti + 4 + i,  t0 = 4,
and it's easy to see that ti = 4i + i(i-1)%2

So, IF the requirement were just to obtain the nth term
in (a f n), we can predict the term using triangular numbers,
2!]  (or -:*<:) :
   fn =: * + 2!] NB. does nicely
   4 fn 7
49
   4 fn >:i.7     NB. it can generate the whole sequence
4 9 15 22 30 39 49

(Note, however,  fa =: fn (>:@i.) performs worse than f !)

It comes into its own for long sequences:
   <.4 fn 7000000
24500024500000
   <.4 {:@f 7000000   NB. also last element of f
24500024500000
ts '<.4 fn 7000000'
7.01939e_6 1664
ts '<.4 {:@f 7000000'  NB. slower and muchgreedier
0.243402 1.34219e8
   Note, however,
   ts '<.4 {:@fa 7000000'NB. as I said!

1.01148 2.01328e8


Any use?
Mike

On 29/09/2017 02:57, Linda Alvord wrote:
Or:
f=: 13 :'+/"1(>:/~i.y)*(y#x)+/i.y'
    4 f 7
4 9 15 22 30 39 49
Linda

Sent from AOL Mobile Mail

On Thursday, September 28, 2017 Raul Miller <[email protected]> wrote:
Nothing is simpler than the i. approach, but ^: is not significantly more complex than 
$: approach: }:(}:,+/@(_2&{.),>:@{:)^:9]4 4 9 15 22 30 39 49 60 72 Thanks, -- 
Raul

On Thu, Sep 28, 2017 at 3:37 PM, Xiao-Yong Jin <[email protected]> wrote: > > >> On Sep 28, 2017, at 1:40 PM, Raul Miller <[email protected]> wrote: >> >> That is what I would assume: >> >> 4,(4+5),(4+5+6),(4+5+6+7),(4+5+6+7+8) >> 4 9 15 22 30 >> >> I was trying to figure out a recursive approach which isn't vastly >> more tedious... > > 4( [, +( ([,+)`$:@.(10>]) ) >:@])5 > > On the other hand, ^: can be used, but I don't see any 
simpler. > >> >> Thanks, >> >> -- >> Raul >> >> >> On Thu, Sep 28, 2017 at 2:39 PM, Roger Hui <[email protected]> wrote: >>> You don't mean >>> >>> +/\4+i.10 >>> 4 9 15 22 30 39 49 60 72 85 >>> >>> do you? >>> >>> >>> >>> On Thu, Sep 28, 2017 at 11:33 AM, Skip Cave <[email protected]> wrote: >>> >>>> What is a good way to generate this sequence in 
J? >>>> >>>> 4,(4+5),(4+5+6),(4+5+6+7),(4+5+6+7+8)+..... >>>> >>>> Show one way using i. and insert. >>>> >>>> Show another way using recursion. >>>> >>>> Skip >>>> >>>> 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 > > ---------------------------------------------------------------------- > 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



---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to