The answer is 73.
$numbers = range(1,100); //define an array with 100 elements starting from 1 to 100
$round = 1; //define a variable to keep note of how many rounds are required to get the answer (this is optional)
$temp = 1; //Just a Boolean variable to remove alternate element
//As removing elements from array will be repetitive task we define a function which will remove elements.
function remove_elements(){
global $numbers, $round, $temp; //Use the variables inside function by defining them global
foreach($numbers as $key=>$value){ //iterate the loop for each element of an array
if($temp == 0) {
unset($numbers[$key]); //remove alternate element
$temp = 1;
}
else {
$temp =0;
}
}
echo "Round $round: ".implode(', ',$numbers)."<br>"; //print the round number and elements remained after removing elements in that round
$round++; //increase the round number for each iteration
if(count($numbers) != 1){
remove_elements(); //we are calling remove_elements function recursively until we are left with only one element in our array
}
}
remove_elements(); //Call the function
Output of this program would be as below:
Round 1: 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99
Round 2: 1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 73, 77, 81, 85, 89, 93, 97
Round 3: 1, 9, 17, 25, 33, 41, 49, 57, 65, 73, 81, 89, 97
Round 4: 9, 25, 41, 57, 73, 89
Round 5: 9, 41, 73
Round 6: 9, 73
Round 7: 73
Check out the detailed description on blog to solve it using programming. http://www.mittalpatel.co.in/solving_puzzle_with_programming