Created
August 28, 2023 13:54
-
-
Save RobertTalbert/ff818256a0bea8d77e2f9c038370360e to your computer and use it in GitHub Desktop.
Python code for exploring the Collatz conjecture
This file contains 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
# Individual Collatz computation | |
def f(n): | |
if n % 2 == 0: | |
return n//2 | |
else: | |
return 3*n+1 | |
# Create sequence of integers from the Collatz function | |
# This assumes the Collatz conjecture is true LOL | |
def collatz(n): | |
result = [ ] | |
while n != 1: | |
result.append(n) | |
n = f(n) | |
result.append(1) | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment