[/color]Enouwem: 73 is the answer!
How?
[color=#006600]Consider a case when there 2^numbers in circle. Each time the number reduces by half and finally at the last number 1 will remain. example – 2^2 = 4 round 1 – 2 and 4 will be killed. round 2 – 3 will be killed. One Remains
So our aim here should be to reach to a figure when 2^n number will come and person who will be holding the sword at that moment will survive.
when there are 100 people – closet 2^number will be 64. so here our target it to find the person who is holding the sword when 64 people are remaining.
64 people remaining means 36 people killed. As every alternate person is being killed so double of 36 i.e 72. So 72 person was killed at that moment and the sword was passed to 73 from 71 after killing 72.
so the moment when 64 people were remaining, 73 was holding the sword, so 73 will survive the killings!!! . . . . . OR, Use the Circular Left Shift methodThere are 100 people. 100 in binary is 1100100. Circular left shift 1100100. We get 1001001. Convert it back to base 10. 73rd is the last man standing. OR, MATHAMATICAL WAY THAT EVERY NIGERIAN WILL UNDERSTANDFirst 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(got sword, passed to 1)
Then 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(sword passed to again)
Then 1,9,17,25,33,41,49,57,65,73,81,89,97(sword passed to 9)
Then 9,25,41,57,73,89(sword passed to 9 again)
Then 9,41,73(sword passed to 9 again)
Then 9,73(73 got sword & killed 9)
Thus the answer is “73"Oh! And for the programmers or coders. PYTHON CODE # find the survivor n = 100 peeps = range(1, n+1) idx = 0 while len(peeps) > 1: peeps.pop((idx + 1) % len(peeps)) # Trivia: because of changing index and len(peeps), # the code below is not exactly equal to "idx = (idx + 1) % len(peeps)" idx = 0 if (idx >= len(peeps)-1) else (idx + 1) print peeps[0] Output: 73 JAVASCRIPT // populate the array for 100 people var team = new Array(); for (var i = 1; i <= 100; i++) { team[i - 1] = i; }
var current; var next;
var j = 0. while (team.length > 1) { // loop until only 1 exists current = team[j]; team.push(team[j]); // move current to the end team.shift(); // remove from existing next = team[j]; team.shift(); // delete next document.writeln("Number " + current + " kills number " + next + "<br />" ; } document.writeln("The last one is number " + team[0]); //alert(team[0]); ikept: My answer is 97th position. This is because after the second cycle of elimination, the total number of people remaining becomes odd. i.e 1st,100/2=50. 2nd, 50/2=25. this makes it impossible to eliminate the last person, which in this case occupies the 97th position. Enouwem: 73 is the answer!
How?
Consider a case when there 2^numbers in circle. Each time the number reduces by half and finally at the last number 1 will remain. example – 2^2 = 4 round 1 – 2 and 4 will be killed. round 2 – 3 will be killed. One Remains
So our aim here should be to reach to a figure when 2^n number will come and person who will be holding the sword at that moment will survive.
when there are 100 people – closet 2^number will be 64. so here our target it to find the person who is holding the sword when 64 people are remaining.
64 people remaining means 36 people killed. As every alternate person is being killed so double of 36 i.e 72. So 72 person was killed at that moment and the sword was passed to 73 from 71 after killing 72.
so the moment when 64 people were remaining, 73 was holding the sword, so 73 will survive the killings!!! . . . . . OR,
Use the Circular Left Shift method
There are 100 people. 100 in binary is 1100100. Circular left shift 1100100. We get 1001001. Convert it back to base 10. 73rd is the last man standing.
OR,
MATHAMATICAL WAY THAT EVERY NIGERIAN WILL UNDERSTAND
First 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(got sword, passed to 1)
Then 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(sword passed to again)
Then 1,9,17,25,33,41,49,57,65,73,81,89,97(sword passed to 9)
Then 9,25,41,57,73,89(sword passed to 9 again)
Then 9,41,73(sword passed to 9 again)
Then 9,73(73 got sword & killed 9)
Thus the answer is “73"
Oh! And for the programmers or coders.
PYTHON CODE
# find the survivor n = 100 peeps = range(1, n+1) idx = 0 while len(peeps) > 1: peeps.pop((idx + 1) % len(peeps)) # Trivia: because of changing index and len(peeps), # the code below is not exactly equal to "idx = (idx + 1) % len(peeps)" idx = 0 if (idx >= len(peeps)-1) else (idx + 1) print peeps[0]
Output: 73
JAVASCRIPT
// populate the array for 100 people var team = new Array(); for (var i = 1; i <= 100; i++) { team[i - 1] = i; }
var current; var next;
var j = 0. while (team.length > 1) { // loop until only 1 exists current = team[j]; team.push(team[j]); // move current to the end team.shift(); // remove from existing next = team[j]; team.shift(); // delete next document.writeln("Number " + current + " kills number " + next + "<br />" ; } document.writeln("The last one is number " + team[0]); //alert(team[0]); |