Tinier

April 15th, 2006

I think this is as small as the amortization program can get without losing functionality. If you can make it smaller, please let me know about it.

def a(p,i,m)j=i/1200;Array.new(m){|n|p=(b=p-k=p*(j/(1-(1+j)**-m))-q=p*j);[n+1,b,q,k]}end

You can still use it the same way. To print a full amortization schedule, for $200,000 at 7.5% interest over 360 months:

puts "month,balance,interest,principle"
a(200000, 7.5, 360).each {|p|printf "%.2f,%.2f,%.2fn",*p}