Created
September 16, 2025 18:54
-
-
Save MurageKibicho/c85cc71880838fecb478d300350dfbb1 to your computer and use it in GitHub Desktop.
JumpCycleSteps
This file contains hidden or 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
| 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