<?php
function BankPay( $BankName , $percent , $servicePayment , $firstServicePayment )
{
$creditBalance = 39999 ; /* Долг анона перед банком */
$monthlyPayment = 5000 ; /* Анон платит 5000 р в месяц, это все, что ему дает мама на завтраки */
$paymentTotal = 0 ; /* Сколько всего отдал банку анон */
for ( $month = 1 ; $month <= 20 ; $month ++ ) {
if ( ( $creditBalance > $monthlyPayment ) && $month == 1 ) {
$creditBalance = ( $creditBalance * $percent ) + $servicePayment + $firstServicePayment - $monthlyPayment ;
$creditBalance = round ( $creditBalance , 2 ) ; } elseif ( $creditBalance > $monthlyPayment ) {
$creditBalance = ( $creditBalance * $percent ) + $servicePayment - $monthlyPayment ;
$creditBalance = round ( $creditBalance , 2 ) ; } else {
$monthlyPayment = $creditBalance ;
$creditBalance = $creditBalance - $monthlyPayment ;
}
$paymentTotal = $paymentTotal + $monthlyPayment ;
$paymentTotal = round ( $paymentTotal , 2 ) ; if ( $creditBalance <= 0 ) {
return $paymentTotal ;
}
}
}
$homoCreditTotal = BankPay( "HomoCredit" , 1.04 , 500 , 0 ) ;
$softBankTotal = BankPay( "SoftBank" , 1.03 , 1000 , 0 ) ;
$strawberryBankTotal = BankPay( "StrawberryBank" , 1.02 , 500 , 7777 ) ;
echo "HomoCredit {$homoCreditTotal} руб. уплачено.\n " ;
echo "SoftBank {$softBankTotal} руб. уплачено.\n " ;
echo "StrawberryBank {$strawberryBankTotal} руб. уплачено.\n " ;
if ( ( $homoCreditTotal <= $softBankTotal ) && ( $homoCreditTotal <= $strawberryBankTotal ) ) {
echo "Лучше всего выбрать HomoCredit банк, в нем надо выплатить всего {$homoCreditTotal} руб." ;
} elseif ( ( $homoCreditTotal >= $softBankTotal ) && ( $homoCreditTotal <= $strawberryBankTotal ) ) {
echo "Лучше всего выбрать SoftBank банк, в нем надо выплатить всего {$softBankTotal} руб." ;
} else {
echo "Лучше всего выбрать StrawberryBank банк, в нем надо выплатить всего {$strawberryBankTotal} руб." ;
}
echo "\n " ;
//Второе решение через массив
echo "Второе решение\n " ;
$BankPayList [ 'HomoCredit' ] = BankPay( "HomoCredit" , 1.04 , 500 , 0 ) ;
$BankPayList [ 'SoftBank' ] = BankPay( "SoftBank" , 1.03 , 1000 , 0 ) ;
$BankPayList [ 'StrawberryBank' ] = BankPay( "StrawberryBank" , 1.02 , 500 , 7777 ) ;
$minBankValue = min ( $BankPayList ) ; echo "Лучший банк это {$minBankKey} , в котором прийдется выплатить {$minBankValue} руб." ;
PD9waHAKZXJyb3JfcmVwb3J0aW5nKC0xKTsKZnVuY3Rpb24gQmFua1BheSgkQmFua05hbWUsICRwZXJjZW50LCAkc2VydmljZVBheW1lbnQsICRmaXJzdFNlcnZpY2VQYXltZW50KQp7CiAgICAkY3JlZGl0QmFsYW5jZSA9IDM5OTk5OyAvKiDQlNC+0LvQsyDQsNC90L7QvdCwINC/0LXRgNC10LQg0LHQsNC90LrQvtC8ICovCiAgICAkbW9udGhseVBheW1lbnQgPSA1MDAwOyAvKiDQkNC90L7QvSDQv9C70LDRgtC40YIgNTAwMCDRgCDQsiDQvNC10YHRj9GGLCDRjdGC0L4g0LLRgdC1LCDRh9GC0L4g0LXQvNGDINC00LDQtdGCINC80LDQvNCwINC90LAg0LfQsNCy0YLRgNCw0LrQuCAqLwogICAgJHBheW1lbnRUb3RhbCA9IDA7IC8qINCh0LrQvtC70YzQutC+INCy0YHQtdCz0L4g0L7RgtC00LDQuyDQsdCw0L3QutGDINCw0L3QvtC9ICovCiAgICBmb3IgKCRtb250aCA9IDE7ICRtb250aCA8PSAyMDsgJG1vbnRoICsrKSB7CiAgICAJaWYgKCgkY3JlZGl0QmFsYW5jZT4kbW9udGhseVBheW1lbnQpJiYkbW9udGg9PTEpIHsKICAgICAgICAgICAgJGNyZWRpdEJhbGFuY2U9KCRjcmVkaXRCYWxhbmNlICogJHBlcmNlbnQgKSArICRzZXJ2aWNlUGF5bWVudCArICRmaXJzdFNlcnZpY2VQYXltZW50IC0gJG1vbnRobHlQYXltZW50OwogICAgICAgICAgICAk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