Created
December 4, 2019 23:37
-
-
Save theideasmith/c33dbbca3918c40b97cce84d192826d6 to your computer and use it in GitHub Desktop.
The 3x+1 Iterator (The Collatz Problem, which you'll soon see gets quite interesting)
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
import matplotlib at plt | |
import numpy as npy | |
def f(arr, n, goal): | |
if n==goal: return arr | |
if arr[-1]%2==0: return f(arr+[(0.5*float(arr[-1]))],n+1,goal) | |
else: return f(arr+[3.0*float(arr[-1])+1], n+1, goal) | |
N = 150 | |
x,y = range(N), f([14],1,N) | |
x2,y2 = range(N), f([14],1,N) | |
plt.plot(x2,y2) | |
plt.figure() | |
plt.plot(x,y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment