Commit 4c2f6ec3 authored by Alexandr Sitchenko's avatar Alexandr Sitchenko

delay

parent 7b137f3e
......@@ -23,38 +23,38 @@ if (((int)$_GET['end'] - (int)$_GET['first']) <= 0) {
exit('The first parameter must be less than the second!');
}
$current = (int)$_GET['first'];
$current = (int)$_GET['end'];
$num = $current;
$ticketsHappy = 0;
do {
/*$sum1 = 0;
$sum2 = 0;*/
$num = $current;
$numbers []= intdiv($current, 1000);
$numbers []= $current%1000;
$sum = [];
foreach($numbers as $key => $num) {
$sumCurrent = 0;
while ($num > 0) {
$sumCurrent += $num % 10;
$num = intdiv($num,10);
}
if ($sumCurrent > 9) {
$sumCurrent = ($sumCurrent % 10) + intdiv($sumCurrent,10);
$currentLeft = intdiv($current, 1000);
$currentRight = $current % 1000;
$sumNumber = static function ($num) {
$sumCurrent = 0;
while ($num > 0) {
$sumCurrent += $num % 10;
$num = intdiv($num, 10);
}
if ($sumCurrent > 9) {
$sumCurrent = ($sumCurrent % 10) + intdiv($sumCurrent, 10);
}
return $sumCurrent;
};
while ($currentLeft >= 0) {
$sumCurrentLeft = $sumNumber($currentLeft);
while ($currentRight >= 0) {
$sumCurrentRight = $sumNumber($currentRight);
if ($sumCurrentLeft === $sumCurrentRight) {
//echo($current.'<br/>');
++$ticketsHappy;
}
$sum []= $sumCurrent;
--$currentRight;
}
if ($sum[0] === $sum[1]) {
//echo($current.'<br/>');
++$ticketsHappy;
if ($currentRight < 0 && $currentLeft > 0) {
$currentRight = 999;
}
unset($numbers,$sum,$sumCurrent);
//$happy($current);
$stopLoop = ($_GET['end'] - $current);
++$current;
} while ($stopLoop);
--$currentLeft;
}
echo $ticketsHappy;
echo '<br /><br />';
echo 'Время выполнения скрипта: ' . round(microtime(true) - $start, 4) . ' сек.';
\ No newline at end of file
echo 'Script execution time: ' . round(microtime(true) - $start, 4) . ' s.';
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment