u^:n y (which we are using here as (next&] ^: (i. 20), so u is next
and n is i. 20 ) applies u to y repeatedly, as many times as necessary
to calculate the largest power in n. Here, u is applied 19 times. The
values after application number 0, 1, 2, etc are saved and put into the
order called for by n .
If you just want the result of applying the verb 19 times, use
next^:19 (1 0)
which discards the intermediate results.
Henry Rich
On 12/20/2012 7:50 AM, alessandro codenotti wrote:
Hope i understood how to answer to a post and that I'm not messing everything
with new threads...
next=.0 3+*&5
20 next@]^:(i.@[) 1 0
Or,
next=.5&(0 3 + *)
(i. 20) next 1 0
Henry Rich
I
cannot understand the first one so I used the second which works
perfectly but, if i correctly understood how it works, it calculate
every term of the sequence starting from the first while it would be
enough to take the last calculated one, multiply it by 5 and then add 3,
with a saving in time and memory that becomes really huge when you need
some thousands of the element in the sequence, correct me if I
misunderstood something in the code.
My question, then, is if the
first code you posted has the same problem and, if the answer is "no",
I'd really appreciate some explanation on how it works!
Otherwise if
the answer is "yes" and both code share this time and memory waste is it
possible to write a code that generate every term working on the last
calculated one avoiding an explicit for cicle?
thank again for the time you're spending helping me!
Alessandro
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm