Lovely solution, using the same idea as Devon's.

As a fan of duals I rewrite it as

   acc2 =: 4 : '+/\&.(%&(*/\ y)) x' "1

acc gives the total value at the beginning of the period.
The other solutions assume deposit at the beginning of the period
and give the interest at the end of the period (I think).  That
would be

    2 -~/\ -/ (d,0) acc2 1 ,:~ 1 + 0,r
50 42 65.52 82.876 87.0198

Henry Rich

---- Roger Hui <[email protected]> wrote: 
> Found it.  Now the question is whether it solves 
> the same problem.
> 
> John Gaboury, Letter to the Editor, APL Quote-Quad,
> Volume 7, Number 4, Winter 1977.
> 
>    acc=: [ (] * +/\@:%) */\...@]
> 
>    r=. 0.05 0.04 0.06 0.05 0.05  NB. interest rates
>    d=. 1000 0 0 500 0            NB. deposits
>    d acc 1+r
> 1000 1040 1102.4 1657.52 1740.4
> 
> 
> 
> ----- Original Message -----
> From: Roger Hui <[email protected]>
> Date: Saturday, July 18, 2009 9:19
> Subject: Re: [Jprogramming] Accumulation, interest, and simulation
> To: Programming forum <[email protected]>
> 
> > There was (I think) a very neat solution APL published
> > in the Quote-Quad in the late 1970s - early 1980s.
> > It was a very short one-liner involving */\ and +/\ .
> > I'll see if I can find it or reproduce it.
> > 
> > Perhaps Joey Tuttle (the keeper of all things) would
> > have a copy of it.  I am pretty sure it would be in
> > one of the IPSA utility workspaces, such as 880 sauce.
> > The function would be called "accum" or some such.
> > 
> > 
> > 
> > ----- Original Message -----
> > From: Bill Harris <[email protected]>
> > Date: Saturday, July 18, 2009 8:20
> > Subject: Re: [Jprogramming] Accumulation, interest, and simulation
> > To: Programming forum <[email protected]>
> > 
> > > Thanks, all.  I figured \. came into it somehow, but I 
> > > didn't get from
> > > there to the end.  I'll study your solutions later today.
> > > 
> > > Bill
> > > 
> > > PS: Thanks for not being misled by my typo in the original Aprime
> > > example, which didn't include the second deposit in the 
> > rolling sum.
> ----------------------------------------------------------------------
> 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