Inspiration
Nothing better than solving a good challenge.
Solution
Its a recursive algorithm made in java to calculate the last person remaining.
int calculateSurvivorPosition(int numPeople) {
if (numPeople == 1){
return 1;
}else{
int result = calculateSurvivorPosition(numPeople - 1);
return (result + 2 - 1) % numPeople + 1;
}
}
There's also an .jar file 'JosephusProblem.jar' attached that runs with double click, on any computer with java on it.
How I built it
I like this kind of challenge so at first I tried to solve it by myself, but then I realized that the solution would not be so simple and that maybe the challenge was a known problem. I decided then to look for it on google and I found about Josephus problem and it's solution.
Accomplishments that I'm proud of
As a thinking ape I believe it's smarter to value and make good use of existing human knowledge, improving it everytime it's possible, instead of trying to reinvent the wheel. That way we can all evolve together. So I'm proud of using a known and optimized solution, and of being honest about it.
What I learned
I learned about Josephus problem and it's solution.
Built With
- brain
- java
Log in or sign up for Devpost to join the conversation.