<?php

function determineTheWinner($pupils, $syllables){
	$arrPupil = array_fill(1, $pupils, 'pupil');
	
	while(count($arrPupil) >= $syllables) {
    $tempArr = $arrPupil;
    end($tempArr);
		
		for($i = $syllables - 1; $i > 0; $i--)	{
			if(key($tempArr) == key($arrPupil)) {
				reset($arrPupil);
				continue;
			}
			
			next($arrPupil);
		}
		
		if(key($tempArr) == key($arrPupil)) {
			unset($arrPupil[key($arrPupil)]);
			reset($arrPupil);
		} else {
			unset($arrPupil[key($arrPupil)]);
		}
		
	}
	
	echo print_r($arrPupil);
}

$total = 30;
$skip = 5;

determineTheWinner($total, $skip);

