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; $sumCurrent = 0;
$numbers []= intdiv($current, 1000); while ($num > 0) {
$numbers []= $current%1000; $sumCurrent += $num % 10;
$sum = []; $num = intdiv($num, 10);
foreach($numbers as $key => $num) { }
$sumCurrent = 0; if ($sumCurrent > 9) {
while ($num > 0) { $sumCurrent = ($sumCurrent % 10) + intdiv($sumCurrent, 10);
$sumCurrent += $num % 10; }
$num = intdiv($num,10); return $sumCurrent;
} };
if ($sumCurrent > 9) { while ($currentLeft >= 0) {
$sumCurrent = ($sumCurrent % 10) + intdiv($sumCurrent,10); $sumCurrentLeft = $sumNumber($currentLeft);
while ($currentRight >= 0) {
$sumCurrentRight = $sumNumber($currentRight);
if ($sumCurrentLeft === $sumCurrentRight) {
//echo($current.'<br/>');
++$ticketsHappy;
} }
$sum []= $sumCurrent; --$currentRight;
} }
if ($sum[0] === $sum[1]) { if ($currentRight < 0 && $currentLeft > 0) {
//echo($current.'<br/>'); $currentRight = 999;
++$ticketsHappy;
} }
unset($numbers,$sum,$sumCurrent); --$currentLeft;
//$happy($current); }
$stopLoop = ($_GET['end'] - $current);
++$current;
} while ($stopLoop);
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