Skip to content

Instantly share code, notes, and snippets.

@Mr-Slippery
Created November 6, 2019 21:01
Show Gist options
  • Save Mr-Slippery/2c6b3e149d0da99d8fc1e3cbe397d86b to your computer and use it in GitHub Desktop.
Save Mr-Slippery/2c6b3e149d0da99d8fc1e3cbe397d86b to your computer and use it in GitHub Desktop.
Find counter examples to the conjecture: The orbit of all strictly positive natural numbers through col3 ends up in one of the two finite cycles.
#!/usr/bin/env python3
"""
Find counter examples to the conjecture:
The orbit of all strictly positive natural numbers
through col3 ends up in either C[0] and C[1].
"""
# Ignores PEP8 and pylint for brevity and math-friendly notation.
import sys
C = [
{1, 6, 2, 9, 3},
# trivial cycle
{21, 7, 30, 10, 42, 14, 57, 19, 78, 26, 105, 35, 141, 47, 189, 63}
# the "other" cycle
]
def col3(n):
"""Collatz-like function based on % 3"""
m = n % 3
if m == 0:
return n / 3
if m == 1:
return 4 * n + 2
if m == 2:
return 4 * n + 1
def cycle(n):
"""Find the cycle in which n ends up"""
start = n
while True:
for i in range(0, 2):
if start in C[i]:
return i
start = col3(start)
def main():
if len(sys.argv) < 2:
return
counter_examples = []
for n in range(1, int(sys.argv[1])):
if cycle(n) > 1:
counter_examples.append(n)
print(counter_examples) # []
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment