Skip to content

Instantly share code, notes, and snippets.

@priyankvex
Created September 5, 2019 14:48
Show Gist options
  • Save priyankvex/293792ebed617dca01ab2704156def4b to your computer and use it in GitHub Desktop.
Save priyankvex/293792ebed617dca01ab2704156def4b to your computer and use it in GitHub Desktop.
Josephus Problem
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