Problem 1092. Decimation
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 well-defined 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
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 crossed-out 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.
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.
test 3 fails. not because of an infinite recursion in my program but owing to the lack of memory. My program is correct
how does this work?
To paraphrase Arthur C Clarke: "Any sufficiently advanced Cody solution from Alfonso is indistinguishable from magic."
Generalized Josephus problem
great solution! (effectively working backwards to get the initial state)
Problem Recent Solvers197
Calculate the Levenshtein distance between two strings
The Hitchhiker's Guide to MATLAB
More from this Author80
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!