fork download
  1. <?php
  2.  
  3. $total = 30;
  4. $skip = 5;
  5. $winnersCount = 4;
  6. $start = 0;
  7.  
  8. $list = range(1, $total);
  9. while (count($list) > $winnersCount) {
  10. $index = ($start + $skip) % count($list) - 1;
  11. array_splice($list, $index, 1);
  12. $start = $index === -1 ? 0 : $index;
  13. }
  14.  
  15. var_dump(join(', ', $list));
Success #stdin #stdout 0s 52488KB
stdin
Standard input is empty
stdout
string(12) "3, 4, 14, 27"