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.
Extracted 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