Problem 1092. Decimation
Solution Stats
Problem Comments

8 Comments
I seem to get 1773 for test case 6.
I also get 1773 for test case 6
I'll look into it a bit later on. In the meantime, that test case is deleted, so you can see if your solutions work for the rest of the test cases.
An interesting test case would have kill_every=1.
Am I the only one who finds the problem description really lacking? WTF does it mean "Because Prisoner 10 was counted during the first iteration,..." IMHO this is just blah and not a welldefined problem definition...
At least 2 of the test cases do not match what I find if I run the sequence by hand on paper. Specifically:
num_prisoners = 30; kill_every = 5;
Survivor is prisoner number 14, not number 3
and,
num_prisoners = 10; kill_every = 10;
Survivor is prisoner number 6, not number 8
Based on other comments, it looks like the test cases may have changed at some point. I believe at least these two (and likely a couple others) are now incorrect.
@Christopher Lanning, decimate(10, 10) = 8 is correct; perhaps you made a mistake on paper. When doing this by hand, it's easiest to count kill_every steps, wrapping around at the end of the line and skipping over crossedout entries (think Eeny Meeny Miny Moo). Prisoner 6 gets killed in the 4th iteration.
Also, I agree with Andrew Newell's earlier comment that there should be a test case for kill_every = 1.
Solution Comments

1 Comment
This fails if kill_every = 1.

2 Comments
I passed test 3 by using a WHILE loop but not a recursive function. IMHO the method should not affect the test cases but in this case it does.
This is a hard one it took me a while to solve it. Thanks God Roman empire has fallen log time ago otherwise I would have no chance to escape decimation.

1 Comment
test 3 fails. not because of an infinite recursion in my program but owing to the lack of memory. My program is correct

1 Comment
really wonderful thought!!! One of the best solution!

4 Comments
how does this work?
To paraphrase Arthur C Clarke: "Any sufficiently advanced Cody solution from Alfonso is indistinguishable from magic."
sdrawkcaB
Generalized Josephus problem

1 Comment
great solution! (effectively working backwards to get the initial state)
Problem Recent Solvers193
Suggested Problems

3940 Solvers

1554 Solvers

Project Euler: Problem 8, Find largest product in a large string of numbers
814 Solvers

Sum of diagonal of a square matrix
1479 Solvers

Return elements unique to either input
725 Solvers
More from this Author80
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!