<?php
function eval_totalpayment($credit, $perc, $commission, $payment, $fee=0) {
$credit+=$fee;
for ($i = 1, $totalpayment = 0, $balance = $credit * (1 + $perc) + $commission; $balance > $payment; ++$i) {
$balance -= $payment;
$balance += $balance * $perc + $commission;
$totalpayment += $payment;
}
$totalpayment += $balance;
echo "Budet oplacheno $totalpayment za $i mecyacev\n";
return $totalpayment;
}
$test = eval_totalpayment(40000, 0.03, 1000, 5000);
PD9waHAKICBmdW5jdGlvbiBldmFsX3RvdGFscGF5bWVudCgkY3JlZGl0LCAkcGVyYywgJGNvbW1pc3Npb24sICRwYXltZW50LCAkZmVlPTApIHsKICAgJGNyZWRpdCs9JGZlZTsKICAgIGZvciAoJGkgPSAxLCAkdG90YWxwYXltZW50ID0gMCwgJGJhbGFuY2UgPSAkY3JlZGl0ICogKDEgKyAkcGVyYykgKyAkY29tbWlzc2lvbjsgJGJhbGFuY2UgPiAkcGF5bWVudDsgKyskaSkgewogICAgICRiYWxhbmNlIC09ICRwYXltZW50OwogICAgICRiYWxhbmNlICs9ICRiYWxhbmNlICogJHBlcmMgKyAkY29tbWlzc2lvbjsKICAgICAkdG90YWxwYXltZW50ICs9ICRwYXltZW50OwogIH0KICAkdG90YWxwYXltZW50ICs9ICRiYWxhbmNlOwogIGVjaG8gIkJ1ZGV0IG9wbGFjaGVubyAkdG90YWxwYXltZW50IHphICRpIG1lY3lhY2V2XG4iOwogIHJldHVybiAkdG90YWxwYXltZW50OwogIH0KICAkdGVzdCA9IGV2YWxfdG90YWxwYXltZW50KDQwMDAwLCAwLjAzLCAxMDAwLCA1MDAwKTs=