Skip to content

Instantly share code, notes, and snippets.

@ahmed4end
Last active August 19, 2020 15:38
Show Gist options
  • Save ahmed4end/abf0e9e1f3e0046b347446e8a30fce66 to your computer and use it in GitHub Desktop.
Save ahmed4end/abf0e9e1f3e0046b347446e8a30fce66 to your computer and use it in GitHub Desktop.
Josephus problem solution in python (simple one).
joseph = lambda x: (lambda j: 1 if x == j else 2*(x-j)+1)(2**[i for i,j in enumerate(bin(x)[:1:-1]) if int(j)][::-1][0])
print(joseph(10))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment