Fail while daring greatly def josephus(n, k): The ancient world “� when men were made of iron and their ships were made of wood � ” could occasionally also be an entertainingly violent place, at least if we believe historical docudramas of swords and sandals such as “300”, “Spartacus” and “Game of Thrones” marred by dust and sweat and blood. (Records from those eras are spotty at best, so shut up, he explained.) During one particularly memorable incident, a group of extremist zealots (yes, Lana, literally) found itself surrounded by overwhelming Roman forces. To avoid capture and death by crucifixion that would have been as humiliating as it was slow, these men chose to commit mass suicide in a way that prevented any one of them from changing his mind. The zealots arranged themselves in a circle and used lots to choose a step size k. From the first man, repeatedly count k men ahead, kill that man and remove his corpse from this grim circle. Being normal people instead of computer scientists, they always start counting from one, not zero. (Their reaction to the idea of zero would have been akin to me asking you in our time what letter comes before the letter A in the English alphabet.)   This deadly game of eeny-meeny-miney-moe continues until the last man standing falls on his own sword to complete the game. Josephus would very much prefer to be this last man since he has other ideas of surviving. Help him survive with a function that, given n and k, returns the list of the execution order so that these men know which places let them be the survivors who get to walk away from this grim circle. A cute mathematical solution can instantly determine the final survivor for k = 2. Unfortunately for us k can get arbitrarily large, even larger than the original number of men… if only to briefly excite us cold and timid souls, hollow men without chests, the rictus of our black lips gaped in grimace that sneers at the strong men who once stumbled.

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

Fail while daring greatly
def josephus(n, k):


The ancient world “� when men were made of iron and their ships were made of wood � ” could occasionally also be an entertainingly violent place, at least if we believe historical docudramas of swords and sandals such as “300”, “Spartacus” and “Game of Thrones” marred by dust and sweat and blood. (Records from those eras are spotty at best, so shut up, he explained.) During one particularly memorable incident, a group of extremist zealots (yes, Lana, literally) found itself surrounded by overwhelming Roman forces. To avoid capture and death by crucifixion that would have been as humiliating as it was slow, these men chose to commit mass suicide in a way that prevented any one of them from changing his mind. The zealots arranged themselves in a circle and used lots to choose a step size k. From the first man, repeatedly count k men ahead, kill that man
and remove his corpse from this grim circle. Being normal people instead of computer scientists, they always start counting from one, not zero. (Their reaction to the idea of zero would have been akin to me asking you in our time what letter comes before the letter A in the English alphabet.)

 

This deadly game of eeny-meeny-miney-moe continues until the last man standing falls on his own sword to complete the game. Josephus would very much prefer to be this last man since he has other ideas of surviving. Help him survive with a function that, given n and k, returns the list of the
execution order so that these men know which places let them be the survivors who get to walk away from this grim circle. A cute mathematical solution can instantly determine the final survivor for k = 2. Unfortunately for us k can get arbitrarily large, even larger than the original number of
men… if only to briefly excite us cold and timid souls, hollow men without chests, the rictus of our black lips gaped in grimace that sneers at the strong men who once stumbled.

k
Expected result
4
1
[1, 2, 3, 4]
4
2
[2, 4, 3, 1]
4
999999
[3, 2, 4, 1]
10
3
[3, 6, 9, 2, 7, 1, 8, 5, 10, 4]
8.
7
[7, 6, 8, 2, 5, 1, 3,
30
[4, 8, 12, 16, 20, 24, 28, 2, 7, 13, 18, 23, 29,
5, 11, 19, 26, 3, 14, 22, 1, 15, 27, 10, 30, 21,
17, 25, 9, 6]
4
(a sequence of 1000 elements whose first five elements are [99,
198, 297, 396, 495] and last five elements are [183, 762,
380, 966, 219])
1000
99
Transcribed Image Text:k Expected result 4 1 [1, 2, 3, 4] 4 2 [2, 4, 3, 1] 4 999999 [3, 2, 4, 1] 10 3 [3, 6, 9, 2, 7, 1, 8, 5, 10, 4] 8. 7 [7, 6, 8, 2, 5, 1, 3, 30 [4, 8, 12, 16, 20, 24, 28, 2, 7, 13, 18, 23, 29, 5, 11, 19, 26, 3, 14, 22, 1, 15, 27, 10, 30, 21, 17, 25, 9, 6] 4 (a sequence of 1000 elements whose first five elements are [99, 198, 297, 396, 495] and last five elements are [183, 762, 380, 966, 219]) 1000 99
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Fundamentals of Boolean Algebra and Digital Logics
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.
Similar questions
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