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
# This is a solution to the Josephus Problem. | |
# This snippet has three parts: | |
# 1. bin(num)[3:] converts an integer to a binary representation and we take the biggest bit in binary with slicing | |
# 3. + "1" add an one to the binary (that we took out previously). | |
# 4. int(num, 2) converts the binary back to decimal | |
def josephus_problem(num): | |
return int(bin(num)[3:] + "1", 2) |