I have been writing this piece of code for a while now, and I was wondering, is it possible to run this code multiple times on my pc? For example could I make the code solve all the numbers from 1 to 1000 and all from 1001 to 2000 at the same time? And, if this is possible, could I use multiple computers to solve it in this way (just with bigger numbers)?
Heres the Code:
#(n*3)+1 = if odd
#else n/2 = if even
import time
import sys
def progress(count, total, status=''):
bar_len = 60
filled_len = int(round(bar_len * count / float(total)))
percents = round(100.0 * count / float(total), 1)
bar = '█' * filled_len + '-' * (bar_len - filled_len)
sys.stdout.write('[%s] %s%s ...%s\r' % (bar, percents, '%', status))
sys.stdout.flush()
one = "nothing"
while one != "n":
if one == "n":
break
else:
total = input("what is the limit number?:")
total = int(total)
total = total+1
highest_step = 0
highest_num = 0
for x in range(0,total):
n = x
steps = 0
print(end="\r")
progress(n, total, status='Doing very long job, current Num:'+str(n))# emulating long-playing job
#print("----IMPOSSIBLE MATH SOLUTION------")
#print()
#print ("staring number is:(",n,")")
#print()
while n != 0:
if n != 1:
if (n%2) == 0:
#print(
eval("n/2")
n = eval("n/2")
steps = steps+1
else:
#print (
eval("(n*3)+1")
n = eval("(n*3)+1")
steps = steps+1
else:
#print ("amount of steps it took to solve:",steps)
if (highest_step <= steps):
highest_step = steps
highest_num = x
break
else:
break
print()
print()
print ("the number with most steps",highest_num)
print ("amount of steps:",highest_step)
one = input("congrats!, do it again? (y/n)")
This would be a great help, thanks
(Also, I am still a beginner coder in python3.)
1 to 1000 [/] 1001 to 2000
Given the relation between argument and run time, that division of labour may need to be refined. There is Python concurrency with modules/packages like concurrent, threading, multiprocessing \$\endgroup\$