Skip to content

Instantly share code, notes, and snippets.

@MurageKibicho
Created September 16, 2025 18:54
Show Gist options
  • Save MurageKibicho/c85cc71880838fecb478d300350dfbb1 to your computer and use it in GitHub Desktop.
Save MurageKibicho/c85cc71880838fecb478d300350dfbb1 to your computer and use it in GitHub Desktop.
JumpCycleSteps
import math
def jump_cycle_steps(k, x0, n):
# Theoretical number of steps until repeat
steps_expected = n // math.gcd(k, n)
print(f"Modulus (n): {n}")
print(f"Jump size (k): {k}")
print(f"Start at x0: {x0}")
print(f"GCD(k, n): {math.gcd(k, n)}")
print(f"Expected cycle length: {steps_expected}")
# Simulate the jumps
seen = set()
x = x0
steps = 0
while x not in seen:
seen.add(x)
x = (x + k) % n
steps += 1
print(f"Simulated steps to return: {steps}")
print(f"Returned to start: {x == x0}")
return steps
# Example usage
k = 45
x0 = 0
n = 45 ** 3
jump_cycle_steps(k, x0, n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment