Created
July 28, 2018 03:45
-
-
Save jmikkola/31dde88f1658258b9bd6a25e4d2aa331 to your computer and use it in GitHub Desktop.
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
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