0
Using itertools.cycle for Josephus problem
I wrote this code to efficiently implement the josephus problem. I wanted to try new python concepts, but I did not get how I can use cycle, and if it would be helpful. I thought that it can help me to iterate through the list (alive) until there is only one last person (1 true value in Boolean list). Or should I just stick to a normal loop? Note: If you have other feedback, how it could work more efficient, please go ahead :) Thanks! https://code.sololearn.com/cHmAMNDOyFqE/?ref=app
1 Réponse
+ 2
There are many ways to solve this, one possible example with cycle() could be like this, based a little on your own code with the list of bool (I think that's a great approach):
https://code.sololearn.com/cPzc3cUQHlNF/?ref=app
But my favorite is the recursive solution.
https://code.sololearn.com/cAlMbk5dNgsm/?ref=app
https://code.sololearn.com/cD4hqMVjVZBQ/?ref=app