Created
September 5, 2019 14:48
-
-
Save priyankvex/293792ebed617dca01ab2704156def4b to your computer and use it in GitHub Desktop.
Josephus Problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution(object): | |
def solve(self, n, k): | |
if n == 1: | |
return 1 | |
else: | |
return (self.solve(n - 1, k) + k - 1) % n + 1 | |
if __name__ == "__main__": | |
n = 41 | |
k = 3 | |
ans = Solution().solve(n, k) | |
print(ans) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment