According to legend, the first century Jewish historian, Flavius Josephus, was captured along with a band of 40 compatriots by Roman soldiers during the Jewish–Roman war. The captured soldiers decided that they preferred suicide to being captured and devised a plan for their demise. They were to form a circle and kill every third soldier until they were all dead. Joseph and one other decided they wanted no part of this and quickly calculated where they needed to place themselves in the circle so that they would both survive. Write a program that allows you to place n people in a circle and specify that every m person will be killed. The program should determine the number of the last person left in the circle. Use a circularly linked list to solve the problem.
According to legend, the first century Jewish historian, Flavius Josephus,
was captured along with a band of 40 compatriots by Roman soldiers during
the Jewish–Roman war. The captured soldiers decided that they preferred
suicide to being captured and devised a plan for their demise. They were
to form a circle and kill every third soldier until they were all dead. Joseph
and one other decided they wanted no part of this and quickly calculated
where they needed to place themselves in the circle so that they would both
survive. Write a
specify that every m person will be killed. The program should determine
the number of the last person left in the circle. Use a circularly linked list
to solve the problem.
Step by step
Solved in 4 steps with 1 images