fork(2) download
  1. vicheslit pmt p com cred = (ms+1,last,total) where
  2. ms = floor $ logBase p ((com-pmt)/((p-1)*cred+com-pmt))
  3. last = p*(cred*p^ms + (p^ms-1)/(p-1)*(com-pmt))+com
  4. total = last+pmt*fromIntegral ms
  5.  
  6. shkolnik pmt (bname,p,com,cred) = fmt $ vicheslit pmt p com cred where
  7. fmt (ms,last,total) = unlines [bname ++ ":",
  8. show ms ++ " months",
  9. "last payment: " ++ show last,
  10. "total paid: " ++ show total]
  11.  
  12. main = mapM_ (putStrLn . shkolnik 5000) [("homoCredit",1.04,500,39999),
  13. ("softBank",1.03,1000,39999),
  14. ("strawberryBank",1.02,0,47776)]
Success #stdin #stdout 0s 6272KB
stdin
Standard input is empty
stdout
homoCredit:
12 months
last payment: 1423.563121624588
total paid: 56423.56312162459

softBank:
13 months
last payment: 1268.7182108072946
total paid: 61268.718210807296

strawberryBank:
11 months
last payment: 3559.8738591998936
total paid: 53559.87385919989