Skip to content

Instantly share code, notes, and snippets.

@crypto-scambaiter
Last active October 2, 2018 02:31
Show Gist options
  • Save crypto-scambaiter/8f77e40acdd1b35a7b637351e164f123 to your computer and use it in GitHub Desktop.
Save crypto-scambaiter/8f77e40acdd1b35a7b637351e164f123 to your computer and use it in GitHub Desktop.
class ax_plus_b:
def __init__(self, a=0, b=0):
self.a = a
self.b = b
def __str__(self):
return '{}*r{:+d}'.format(self.a, self.b)
def substitute_for_x(self, x_expr):
return ax_plus_b(self.a * x_expr.a, self.a * x_expr.b + self.b)
def even_branch(self):
if self.a % 2 == 1:
x_for_even = ax_plus_b(2, -1 if self.b % 2 == 1 else 0)
return self.substitute_for_x(x_for_even), x_for_even
else:
return None
def odd_branch(self):
if self.a % 2 == 1:
x_for_odd = ax_plus_b(2, 0 if self.b % 2 == 1 else -1)
return self.substitute_for_x(x_for_odd), x_for_odd
return None
def seeds_by_trajectory(traj):
if traj[0] == '0':
k = ax_plus_b(2, 0)
t = ax_plus_b(1, 0)
else:
k = ax_plus_b(2, -1)
t = ax_plus_b(3, -1)
for s in traj[1:]:
if s == '0':
t, p = t.even_branch()
else:
t, p = t.odd_branch()
t.a *= 3
t.b = 3 * t.b + 1
t.a //= 2
t.b //= 2
k = k.substitute_for_x(p)
return k, t
if __name__ == "__main__":
traj = '110110110101101101011011011010110110101101101101011011010110110110101101101011011010110110110101101101'
k, t = seeds_by_trajectory(traj)
print('Trajectory', traj, ' start =', k, ' end =', t, ' pick any r = 1,2,3,...')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment