Skip to content

Instantly share code, notes, and snippets.

View TheXer's full-sized avatar
👻
Boo Boo!

Robert Sokola TheXer

👻
Boo Boo!
  • Brno, Czech Republic
View GitHub Profile
@TheXer
TheXer / josephus_problem.py
Created August 25, 2021 18:52
Josephus problem solution in Python
# 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)