Skip to content

Instantly share code, notes, and snippets.

@jmikkola
Created July 28, 2018 03:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmikkola/31dde88f1658258b9bd6a25e4d2aa331 to your computer and use it in GitHub Desktop.
Save jmikkola/31dde88f1658258b9bd6a25e4d2aa331 to your computer and use it in GitHub Desktop.
mem = {}
def collatz_len(n):
if n < 2:
return 1
if n not in mem:
chain = 1 + collatz_len(n/2 if n%2 == 0 else 3*n + 1)
mem[n] = chain
return mem[n]
def histo_bar(n):
return '=' * n
X = 13
histo = {n: 0 for n in range(X)}
Y = 1000000
for i in range(Y):
n = collatz_len(i)
histo[n % X] += 1
for i in range(X):
n = int(histo[i] / 1000)
print(histo_bar(n))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment