Question: Roman Roulette: Purpose In this problem, you will learn how to use a computer to solve a thorny historical problem. You will also get to
Roman Roulette:
Purpose
In this problem, you will learn how to use a computer to solve a thorny historical problem. You will also get to exercise your programming and think before coding skills. It is also an exercise to show how math can save lives. Also called "AfterMath:
Background
The historian H relates how, in the conflict of CE the Romans took the town of P which he was commanding. Escaping, H found himself trapped in a cave with companions. The Romans discovered his whereabouts and invited him to surrender, but his companions refused to allow him to do so He therefore suggested that they kill each other, one by one, the order to be decided by lot. Tradition has it that the means for effecting the lot was to stand in a circle, and, beginning at some point, count round, every third person being killed in turn. The sole survivor of this process was H who then surrendered to the Romans. Which begs the question: had H previously practiced quietly with stones in a dark corner, or had he calculated mathematically that he should adopt the st position in order to survive?
Having read an account of this gruesome event you become obsessed with the fear that you will find yourself in a similar situation at some time in the future. In order to prepare yourself for such an eventuality you decide to write a program to run on your mobile phone which will determine the position in which you should stand to ensure that you will be the sole survivor.
In particular, your program should be able to handle the following processes. n people are initially arranged in a circle, facing inwards, and numbered from to n clockwise. The numbering from to n proceeds consecutively in a clockwise direction. Starting with person number counting starts in a clockwise direction, until we get to person number k k who is promptly killed. We then proceed to count a further k people in a clockwise direction, starting with the person immediately to the left of the victim that is the victims left That kth person is killed next, and so on until only one person remains.
For example, when n and k the players are eliminated in order, and player wins. If n and k the order of elimination is and player wins. Note that players are not renumbered after each death: everyone keeps their initial number until the end or their end
Note that when we count k we would need to skip over a dead person. eg If we are at alive and k and # an # are dead, and # and # are alive, then we will hop over # and # and go from # to # and # to # This would make it steps from # to # and # would be killed.
Statement of Work
Write a program to solve the H problem for general values of n and k Your program must read the values of n and k from cin and write the winners for to cout. Each problem will be on its own input line containing values for n and k in that order For each input problem, your program should output a single line containing only the number of the survivor so youll know in which position to stand Your program may assume that both n and k can be held by int variables.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
