-
Notifications
You must be signed in to change notification settings - Fork 0
/
collatz_fast.py
50 lines (40 loc) · 1.29 KB
/
collatz_fast.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import time
temptime = time.perf_counter()
time.sleep(1)
print(time.perf_counter()-temptime, end='')
print('should be about equal to 1.000000000000')
working = 0
lastvalue = 0
runningtally = 0
count = 0
highestcount = 0
currentvalue = 1
if currentvalue % 2 == 0:
currentvalue += 1
starttime = time.perf_counter()
while (True):
if ((runningtally % 500001) <= 0):
snaptime = time.perf_counter()
elapsedmilliseconds = round((snaptime-starttime)*1000)
print(elapsedmilliseconds, end='')
#ps = runningtally / snaptime
ps = round(runningtally / (elapsedmilliseconds+1))
print("ms steps/ms: " + str(ps) + " total steps: " + str(runningtally) + ", last number's stepcount:" + str(count))
elif count > highestcount:
highestcount = count
timestamp = time.ctime(time.time())
print()
print(str(timestamp) + " New record: " + str(highestcount) + ", on: " + str(currentvalue) + ".")
lastvalue = currentvalue
currentvalue += 2
count = 1
working = currentvalue
while working > 1:
if working <= lastvalue:
break
elif working % 2 == 0:
working = working / 2
else:
working = ((working*3) +1) / 2
count += 1
runningtally += 1