<?php
$total = 7;
$skip = 4;
//создаем массив для хранения участников
//заполняем массив участниками жеребьевки
for ($i = 0; $i < $total; $i++) {
$humans[$i] = $i + 1;
}
function oneDraw($humans, $skip) {
//находим сколько участников не вошло в жеребьевку,
//с этой части будет начинаться новый тур жеребьевки
$humansEnd = count($humans) % $skip;
echo "======================== \n";
echo "на входе: \n";
//удаляем проигравших
$length = count($humans); for ($i = 0, $j = 0; $i < $length; $i++) {
$j++;
if ($j == $skip) {
$j = 0;
}
}
echo "после удаления: \n";
//переносим людей в начало массива, жеребьевка будем начинать с них;
while ($humansEnd > 0) {
$humansEnd--;
}
echo "на выходе: \n";
echo "======================== \n";
echo "\n";
}
function multiDrow($oneDrow, $skip) {
$countDrow = count($oneDrow); if ($countDrow < $skip) {
return $oneDrow;
} else {
return multiDrow(oneDraw($oneDrow, $skip), $skip);
}
}
$result = multiDrow(oneDraw($humans, $skip), $skip);
echo "Выигрышные места: ";
foreach ($result as $value) {
echo "{$value} ";
}
//$draw1 = oneDraw($humans, $skip);
//$draw2 = oneDraw($draw1, $skip);
//$draw3 = oneDraw($draw2, $skip);
//$draw4 = oneDraw($draw3, $skip);
//
//foreach ($draw1 as $human) {
// echo "{$human} ";
//}
//
//echo "\n";
//
//foreach ($draw2 as $human1) {
// echo "{$human1} ";
//}
//
//echo "\n";
//
//foreach ($draw3 as $human2) {
// echo "{$human2} ";
//}
//
//echo "\n";
//
//foreach ($draw4 as $human2) {
// echo "{$human2} ";
//}
PD9waHAKCiR0b3RhbCA9IDc7CiRza2lwID0gNDsKCi8v0YHQvtC30LTQsNC10Lwg0LzQsNGB0YHQuNCyINC00LvRjyDRhdGA0LDQvdC10L3QuNGPINGD0YfQsNGB0YLQvdC40LrQvtCyCiRodW1hbnMgPSBhcnJheSgpOwoKLy/Qt9Cw0L/QvtC70L3Rj9C10Lwg0LzQsNGB0YHQuNCyINGD0YfQsNGB0YLQvdC40LrQsNC80Lgg0LbQtdGA0LXQsdGM0LXQstC60LgKZm9yICgk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