Last active
July 30, 2021 22:31
-
-
Save softyoda/52efbf7f520cba7e56779b3271df8d68 to your computer and use it in GitHub Desktop.
Just a small python programm to bruteforce 421 (idea from this video https://www.youtube.com/watch?v=094y1Z2wpJg& )
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 random, time, sys | |
def trybignumber(bignumber): | |
num = random.getrandbits(bignumber) | |
print(num) | |
file = open("number.txt", "w") | |
file.write("Current number : \n"+ str(num)) | |
file.close | |
loop = 0 | |
start = time.time() | |
prev_time = time.time() | |
while num != 1: | |
loop +=1 | |
if num % 2 == 0: | |
num = int(num//2) | |
else: | |
num = num*3+1 | |
dt = time.time() - prev_time | |
if dt > 1: | |
print("Size of the number : ", sys.getsizeof(num) , "Bytes. Number of steps : ", loop ) | |
prev_time = time.time() | |
end = time.time() | |
print("The number converges in ", end-start ," seconds and ", loop , "steps.") | |
for i in range(100): | |
trybignumber(2**20) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There is also this code that try smaller numbers but stop when the number decrease.