A very intelligent and kind Traveller was trapped by a King, King wants to check his intelligence and kindness at the same time.
So he sets up a scenario where he asks traveller to play the “Sword Killing” game.
In this game ’N’ number of people have to stand in a circle in an order 1 to ’N’ and someone of them has a Sword, so when the game starts the person with the sword kills the left adjacent person and passes the sword to the next person, next person do the same again and this keeps on going until only one person survives at the end.
For example: – At starting, Person at 18th position have the sword, and the game starts, then the 18th position person kills 19th position person and passes sword to 20th position person, 20th person kills 21st person and passes sword to 22nd person and so on till only one person survives.
The twist King makes is that, he make the traveller stand at 489th position in the circle, and asks traveller to choose any number of people he wants to make stand in the circle, where traveller’s position will be fixed (489th) and also gave him option for starting this game from any position (Sword Initially with this position) . The basic rules for the game still remains same.
==>> SP (Starting Position): – Position of person the game starts from.
e.g. if SP=103 >> At starting Person at 103th position have the sword, and the game starts in a way that he kills 104 and passes it to 105 and so on till only one survives, which in this case should be 489th position person.
==>> N :- Total no. of people standing in the circle at the starting. N includes traveller as well.
For e.g. if N=500, it includes person standing at 489(or the traveller himself).
It is also understandable that N>=489
==>> Traveller is very Kind and wants to kill least no. of people as possible. Although he is kind but he prioritises his life over others.
i.e. he wants to save himself, but by killing minimum no. of people.
So you need to determine what would be value of N and SP, if Traveller wants to prove his kindness and intelligence.
Check your answer:
Value of N
Answer: N = 489, SP = 223
We know that at the end only 1 person will survive, so he should handover the sword to a person such that he himself survives at the end. also to minimize the death’s N should be 489, as N can’t be smaller than 489 and if we add more persons, it means more people will die.
Now, it is important to notice that, if the number is a complete power of 2, the person who starts it survives.
Why? as lets assume we have 2^n persons, now after the round 1, half of the persons will be killed and the sword will be with the first person(who started) and now 2^(n-1) people will remain. and this will go one till 2^(1-1) = 2^0 = 1 person will remain(that will be the one who started it).
Now let’s find out the complete of 2 smaller than 489.
it is 256.
Now, if he ask someone to start such that when the sword comes to him, exactly 256 people should remain, he will survive at the end.
to do this, 489-256 = 233 people should die first.
thus if he asks 489 – 2*233 = 489 – 466 = 23rd person to start, when the sword will reach 489th person, 233 people will be dead with 256 people remaining. and we already proved that if total number of persons are a complete power of 2, person who starts survives.