<?php
function totalPayment($creditSum, $percent, $monthlyPayment, $servicePayment, $newAccPayment) {
$paymentTotal = 0;
$creditSum += $newAccPayment;
while ($creditSum > 0) {
$creditSum = ($creditSum * $percent) + $servicePayment;
if ($creditSum < $monthlyPayment) {
$monthlyPayment = $creditSum;
}
$creditSum -= $monthlyPayment;
$paymentTotal = $paymentTotal + $monthlyPayment;
}
return $paymentTotal;
}
$creditSum = 39999;
$monthlyPayment = 5000;
$homoCredit = totalPayment($creditSum, 1.04, $monthlyPayment, 500, 0);
$softBank = totalPayment($creditSum, 1.03, $monthlyPayment, 1000, 0);
$strawberryBank = totalPayment($creditSum, 1.02, $monthlyPayment, 0, 7777);
echo "homoCredit: {$homoCredit} roubles.\n";
echo "softBank: {$softBank} roubles.\n";
echo "strawberryBank: {$strawberryBank} roubles.\n";
PD9waHAKCmVycm9yX3JlcG9ydGluZygtMSk7CgpmdW5jdGlvbiB0b3RhbFBheW1lbnQoJGNyZWRpdFN1bSwgJHBlcmNlbnQsICRtb250aGx5UGF5bWVudCwgJHNlcnZpY2VQYXltZW50LCAkbmV3QWNjUGF5bWVudCkgewogICAgJHBheW1lbnRUb3RhbCA9IDA7IAogICAgJGNyZWRpdFN1bSArPSAkbmV3QWNjUGF5bWVudDsKICAgIHdoaWxlICgkY3JlZGl0U3VtID4gMCkgewogICAgICAgICRjcmVkaXRTdW0gPSAoJGNyZWRpdFN1bSAqICRwZXJjZW50KSArICRzZXJ2aWNlUGF5bWVudDsKICAgICAgICBpZiAoJGNyZWRpdFN1bSA8ICRtb250aGx5UGF5bWVudCkgewogICAgICAgICAgICAkbW9udGhseVBheW1lbnQgPSAkY3JlZGl0U3VtOyAKICAgICAgICB9ICAgICAgIAogICAgICAgICRjcmVkaXRTdW0gLT0gJG1vbnRobHlQYXltZW50OwkKICAgICAgICAkcGF5bWVudFRvdGFsID0gJHBheW1lbnRUb3RhbCArICRtb250aGx5UGF5bWVudDsKICAgIH0KICAgIHJldHVybiAkcGF5bWVudFRvdGFsOwp9CgokY3JlZGl0U3VtID0gMzk5OTk7CiRtb250aGx5UGF5bWVudCA9IDUwMDA7CiRob21vQ3JlZGl0ID0gdG90YWxQYXltZW50KCRjcmVkaXRTdW0sIDEuMDQsICRtb250aGx5UGF5bWVudCwgNTAwLCAwKTsKJHNvZnRCYW5rID0gdG90YWxQYXltZW50KCRjcmVkaXRTdW0sIDEuMDMsICRtb250aGx5UGF5bWVudCwgMTAwMCwgMCk7CiRzdHJhd2JlcnJ5QmFuayA9IHRvdGFsUGF5bWVudCgkY3JlZGl0U3VtLCAxLjAyLCAkbW9udGhseVBheW1lbnQsIDAsIDc3NzcpOwplY2hvICJob21vQ3JlZGl0OiB7JGhvbW9DcmVkaXR9IHJvdWJsZXMuXG4iOwplY2hvICJzb2Z0QmFuazogeyRzb2Z0QmFua30gcm91Ymxlcy5cbiI7CmVjaG8gInN0cmF3YmVycnlCYW5rOiB7JHN0cmF3YmVycnlCYW5rfSByb3VibGVzLlxuIjsK