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) { ...@@ -23,38 +23,38 @@ if (((int)$_GET['end'] - (int)$_GET['first']) <= 0) {
exit('The first parameter must be less than the second!'); exit('The first parameter must be less than the second!');
} }
$current = (int)$_GET['first']; $current = (int)$_GET['end'];
$num = $current; $num = $current;
$ticketsHappy = 0; $ticketsHappy = 0;
do { $currentLeft = intdiv($current, 1000);
/*$sum1 = 0; $currentRight = $current % 1000;
$sum2 = 0;*/ $sumNumber = static function ($num) {
$num = $current;
$numbers []= intdiv($current, 1000);
$numbers []= $current%1000;
$sum = [];
foreach($numbers as $key => $num) {
$sumCurrent = 0; $sumCurrent = 0;
while ($num > 0) { while ($num > 0) {
$sumCurrent += $num % 10; $sumCurrent += $num % 10;
$num = intdiv($num,10); $num = intdiv($num, 10);
} }
if ($sumCurrent > 9) { if ($sumCurrent > 9) {
$sumCurrent = ($sumCurrent % 10) + intdiv($sumCurrent,10); $sumCurrent = ($sumCurrent % 10) + intdiv($sumCurrent, 10);
} }
$sum []= $sumCurrent; return $sumCurrent;
} };
if ($sum[0] === $sum[1]) { while ($currentLeft >= 0) {
$sumCurrentLeft = $sumNumber($currentLeft);
while ($currentRight >= 0) {
$sumCurrentRight = $sumNumber($currentRight);
if ($sumCurrentLeft === $sumCurrentRight) {
//echo($current.'<br/>'); //echo($current.'<br/>');
++$ticketsHappy; ++$ticketsHappy;
} }
unset($numbers,$sum,$sumCurrent); --$currentRight;
//$happy($current); }
$stopLoop = ($_GET['end'] - $current); if ($currentRight < 0 && $currentLeft > 0) {
++$current; $currentRight = 999;
} while ($stopLoop); }
--$currentLeft;
}
echo $ticketsHappy; echo $ticketsHappy;
echo '<br /><br />'; echo '<br /><br />';
echo 'Время выполнения скрипта: ' . round(microtime(true) - $start, 4) . ' сек.'; echo 'Script execution time: ' . round(microtime(true) - $start, 4) . ' s.';
\ No newline at end of file \ 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