Skip to content

Instantly share code, notes, and snippets.

View tzaffi's full-sized avatar
🐙
Octopii are cool

Zeph Grunschlag tzaffi

🐙
Octopii are cool
View GitHub Profile
@tzaffi
tzaffi / generalized_josephus.py
Created September 29, 2014 06:14
Solution to the generalized Josephus problem
def generalized_josephus(self, x):
# express x as a radix d number-sequence
rad_d = Radix.tuple(x, base=self.d)
# then apply the generalized josephus transformation to convert to a radix c number-sequence
rad_c = [self.alpha_vector[rad_d[0]-1]]
for dig in rad_d[1:]:
rad_c.append(self.beta_vector[dig])
# convert rad_c to a number and return