Paste: payments
Author: | fred |
Mode: | factor |
Date: | Wed, 31 Dec 2008 20:37:08 |
Plain Text |
USING: io kernel math math.parser ;
IN: payments
: interest-rate ( -- rate )
.02 12 / ;
: initial-balance ( -- balance )
500 ;
: total-to-pay ( -- amt )
587 ;
: number-of-payments ( -- n )
6 ;
: monthly-payment ( -- payment )
total-to-pay number-of-payments / ;
: collect-interest ( rate balance -- rate balance )
2dup * + ;
: payment ( rate balance payment -- rate balance payment )
[ collect-interest ] dip [ - ] keep ;
: do-it ( -- )
interest-rate initial-balance monthly-payment
number-of-payments [ payment ] times rot 2drop number>string print ;
Author: | fred |
Mode: | factor |
Date: | Wed, 31 Dec 2008 21:30:21 |
Plain Text |
USING: io kernel math math.parser ;
IN: payments
: interest-rate ( -- rate )
.02 12 / ;
: initial-balance
500 ;
: total-to-pay
587 ;
: number-of-payments
6 ;
: monthly-payment ( -- payment )
total-to-pay number-of-payments / ;
: collect-interest ( balance -- new-balance )
dup interest-rate * + ;
: payment ( balance -- new-balance )
collect-interest monthly-payment - ;
: do-it ( -- )
initial-balance number-of-payments [ payment ] times
number>string print ;
MAIN: do-it
New Annotation