fork download
  1. <?php
  2.  
  3. function determineTheWinner($pupils, $syllables){
  4. $arrPupil = array_fill(1, $pupils, 'pupil');
  5.  
  6. while(count($arrPupil) >= $syllables) {
  7. $tempArr = $arrPupil;
  8. end($tempArr);
  9.  
  10. for($i = $syllables - 1; $i > 0; $i--) {
  11. if(key($tempArr) == key($arrPupil)) {
  12. reset($arrPupil);
  13. continue;
  14. }
  15.  
  16. next($arrPupil);
  17. }
  18.  
  19. if(key($tempArr) == key($arrPupil)) {
  20. unset($arrPupil[key($arrPupil)]);
  21. reset($arrPupil);
  22. } else {
  23. unset($arrPupil[key($arrPupil)]);
  24. }
  25.  
  26. }
  27.  
  28. echo print_r($arrPupil);
  29. }
  30.  
  31. $total = 30;
  32. $skip = 5;
  33.  
  34. determineTheWinner($total, $skip);
  35.  
  36.  
Success #stdin #stdout 0.03s 24100KB
stdin
Standard input is empty
stdout
Array
(
    [3] => pupil
    [4] => pupil
    [14] => pupil
    [27] => pupil
)
1