A popular riddle which you should attempt if you have never came across it.
100 Soldiers are standing in a circle in an order 1 to 100.
No.1 has a sword.
He kills next person (i.e. no. 2) and gives sword to next to next (i.e no.3).
All the soldiers do the same until only 1 survives.
So were you able to solve the riddle? Leave your answers in the comment section below.
You can check if your answer is correct by clicking on show answer below. If you get the right answer, please do share the riddle with your friends and family on WhatsApp, Facebook and other social networking sites.
Answer:
The straight forward way of solving this qould be manually writing down 1 to 100 and then striking out the numbers as per the problem.
In such a scenario it would go like this;
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
so answer is 73
what if their were 1000 soldiers??
would it be possible to solve it by this method??
Yes but it would consume a lot of time.
Here’s the correct way of solving this riddle.
This is actually a classic Josephus Problem.
The original Josephus Problem goes like this;
“The problem is named after Flavius Josephus, a Jewish historian living in the 1st century. According to Josephus’ account of the siege of Yodfat, he and his 40 soldiers were trapped in a cave, the exit of which was blocked by Romans. They chose suicide over capture and decided that they would form a circle and start killing themselves using a step of three. Josephus states that by luck or possibly by the hand of God, he and another man remained the last and gave up to the Romans.”
Solution to the Riddle using Josephus Problem approach:
The solution requires getting the nearest smaller number that is the power of 2, in this case 64 and subtract it with the given number.100-64=36.
Now we apply the formula;
2n+1 = 2*36 + 1 = 72 + 1 = 73.
Hence answer = 73
import java.io.*;
import java.util.*;
public class Solution
{
public static void main(String[] args)
{
int a,b;
Scanner sc=new Scanner(System.in);
a=sc.nextInt();
b=a;
int[] arr= new int[40];
int index=0;
int[] ar= new int[40];
int[] arrr= new int[40];
while(b > 0)
{
arr[index++] = b%2;
b = b/2;
}
for(int k=0;k<index;k++)
{
ar[k]=arr[index-k-1];
}
for(int l=0;l<index-1;l++)
{
arrr[l]=ar[l+1];
}
arrr[index-1]=ar[0];
int total=0;
for(int g = 0; g < index; g++)
{
total += Math.pow(2,g) * arrr[index – g – 1];
}
System.out.println(total);
}
}
I got the Josephus problem…but 73 is the correct answer because they wanted to suicide but if we see the riddle here…9, 41, and 73 will be in the last round but if they are forced to do this…then 9 will kill 41 but won’t give the sword to 73..just to kill himself…i mean that way 9 could be the survivor. I mean i got the mathematics but actually didnt get the logic…plz someone explain..
at the end of the second round wouldnt number 97 be left with the sword? and therefore have to kill number 1?
How we got 64 out of that? And what is Answer of 1000 men?
Hi Nilan,
You can google for “Josephus Problem” for further explanation on the theory.
It’s an interesting concept but needs deeper reading.
Thanks