Last active
August 10, 2016 09:13
-
-
Save Spriithy/e226fffba599ef57f250d761dbc027d6 to your computer and use it in GitHub Desktop.
Simple calculation program for the 3x+1 problem
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 time | |
it = 0 | |
L = [] | |
i = 1 | |
mi = 0 | |
mv = 1 | |
dt = time.time() | |
while i <= 1000000: | |
d = time.time() | |
j = i | |
t = 0 | |
print('----= Checking ' + str(int(i)) + ' =----') | |
while not j in L: | |
if j == 1: | |
break | |
else: | |
print('[iteration:' + str(it) + ']\tInserted:\t' + str(int(j))) | |
L.append(int(j)) | |
if j % 2 == 0: | |
j /= 2 | |
else: | |
j = 3 * j + 1 | |
t += 1 | |
it += 1 | |
print('[iteration:' + str(it) + ']\tValidated ' + str(int(i)) + ' with ' + str(t) + ' iterations in ' + str(d - dt) + 's.') | |
dt = d | |
if t > mi: | |
mi = t | |
mv = i | |
i += 1 | |
it += 1 | |
print('-------------------------------------------------') | |
print('Max iterations for: ' + str(int(mv)) + ' in ' + str(mi) + ' iterations.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment