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 67 C.E., the Romans took the town of P which he was commanding. Escaping, H found himself trapped in a cave with 40 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 41 stones in a dark corner, or had he calculated mathematically that he should adopt the 31st 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 > 0 people are initially arranged in a circle, facing inwards, and numbered from 1 to n clockwise. The numbering from 1 to n proceeds consecutively in a clockwise direction. Starting with person number 1, counting starts in a clockwise direction, until we get to person number k (k > 0), 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 victim's left). That kth person is killed next, and so on, until only one person remains. For example, when n = 5, and k = 1, the players are eliminated in order, and player 5 wins. If n = 5 and k = 2, the order of elimination is 2, 4, 1, 5, and player 3 wins. Note that players are not renumbered after each death: everyone keeps their initial number until the end (or their end). Statement of Work Write a program to solve the H problem for general values of n > 0 and k ≥ 0. 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 you'll know in which position to stand). Your program may assume that both n and k can be held by int variables OUTPUT (Note I have numbered my data from 0 to n-1, but final answer is adjusted by 1 for actual position) Please enter number of people and step :5 2 finding live 0 incrementing to 1 killed 1 finding live 2 incrementing to 3 killed 3 finding live 4 incrementing to 0 killed 0 finding live 2 incrementing to 4 killed 4 survivor is #3

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

In C++ please

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 67 C.E., the Romans took the town of P which he was commanding.
Escaping, H found himself trapped in a cave with 40 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 41 stones in
a dark corner, or had he calculated mathematically that he should adopt the 31st 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 > 0 people are initially arranged in a
circle, facing inwards, and numbered from 1 to n clockwise. The numbering from 1 to n proceeds consecutively in a
clockwise direction. Starting with person number 1, counting starts in a clockwise direction, until we get to person
number k (k > 0), 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 victim's left). That kth person is killed next, and so on,
until only one person remains.
For example, when n = 5, and k = 1, the players are eliminated in order, and player 5 wins. If n = 5 and k = 2, the order of
elimination is 2, 4, 1, 5, and player 3 wins. Note that players are not renumbered after each death: everyone keeps their
initial number until the end (or their end).
Statement of Work
Write a program to solve the H problem for general values of n > 0 and k ≥ 0. 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 you'll know in which position to stand). Your program may assume that both n and k can be held
by int variables
OUTPUT (Note I have numbered my data from 0 to n-1, but final answer is adjusted by 1 for actual position)
Please enter number of people and step :5 2
finding live 0
incrementing to 1
killed 1
finding live 2
incrementing to 3
killed 3
finding live 4
incrementing to 0
killed 0
finding live 2
incrementing to 4
killed 4
survivor is #3
Transcribed Image Text: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 67 C.E., the Romans took the town of P which he was commanding. Escaping, H found himself trapped in a cave with 40 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 41 stones in a dark corner, or had he calculated mathematically that he should adopt the 31st 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 > 0 people are initially arranged in a circle, facing inwards, and numbered from 1 to n clockwise. The numbering from 1 to n proceeds consecutively in a clockwise direction. Starting with person number 1, counting starts in a clockwise direction, until we get to person number k (k > 0), 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 victim's left). That kth person is killed next, and so on, until only one person remains. For example, when n = 5, and k = 1, the players are eliminated in order, and player 5 wins. If n = 5 and k = 2, the order of elimination is 2, 4, 1, 5, and player 3 wins. Note that players are not renumbered after each death: everyone keeps their initial number until the end (or their end). Statement of Work Write a program to solve the H problem for general values of n > 0 and k ≥ 0. 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 you'll know in which position to stand). Your program may assume that both n and k can be held by int variables OUTPUT (Note I have numbered my data from 0 to n-1, but final answer is adjusted by 1 for actual position) Please enter number of people and step :5 2 finding live 0 incrementing to 1 killed 1 finding live 2 incrementing to 3 killed 3 finding live 4 incrementing to 0 killed 0 finding live 2 incrementing to 4 killed 4 survivor is #3
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Mathematical functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education