<?php
function calculateCredit($percent, $monthlyFee, $onceFee, $creditSum, $payout) {
$sum = $creditSum + $onceFee;
$totalSum = 0;
for ($i=0; $i < 369; $i++) {
$sum = $sum * $percent + $monthlyFee;
if ($sum >= $payout) {
$sum -= $payout;
$totalSum += $payout;
} else {
$totalSum += $sum;
break;
}
}
return $totalSum;
}
$creditSum = 39999;
$payout = 5000;
$homoCreditTotal = calculateCredit(1.04, 500, 0, $creditSum, $payout);
$softbankTotal = calculateCredit(1.03, 1000, 0, $creditSum, $payout);
$strawberryBankTotal = calculateCredit(1.02, 0, 7777, $creditSum, $payout);
echo "homoCredit: {$homoCreditTotal} руб. \n";
echo "softbank: {$softbankTotal} руб. \n";
echo "strawberryBank: {$strawberryBankTotal} руб. \n";
PD9waHAKIAplcnJvcl9yZXBvcnRpbmcoLTEpOwogCmZ1bmN0aW9uIGNhbGN1bGF0ZUNyZWRpdCgkcGVyY2VudCwgJG1vbnRobHlGZWUsICRvbmNlRmVlLCAkY3JlZGl0U3VtLCAkcGF5b3V0KSB7Cgkkc3VtID0gJGNyZWRpdFN1bSArICRvbmNlRmVlOwoJJHRvdGFsU3VtID0gMDsKCWZvciAoJGk9MDsgJGkgPCAzNjk7ICRpKyspIHsgCgkJJHN1bSA9ICRzdW0gKiAkcGVyY2VudCArICRtb250aGx5RmVlOwoJCWlmICgkc3VtID49ICRwYXlvdXQpIHsKCQkJJHN1bSAtPSAkcGF5b3V0OwoJCQkkdG90YWxTdW0gKz0gJHBheW91dDsKCQl9IGVsc2UgewoJCQkkdG90YWxTdW0gKz0gJHN1bTsKCQkJYnJlYWs7CgkJfQoJfQoJcmV0dXJuICR0b3RhbFN1bTsKfQogCiRjcmVkaXRTdW0gPSAzOTk5OTsKJHBheW91dCA9IDUwMDA7CiRob21vQ3JlZGl0VG90YWwgPSBjYWxjdWxhdGVDcmVkaXQoMS4wNCwgNTAwLCAwLCAkY3JlZGl0U3VtLCAkcGF5b3V0KTsKJHNvZnRiYW5rVG90YWwgPSBjY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