/ Published in: Python
Cool little code that will test the Collatz conjecture
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
def mathprob_no_print(x): while x != 1: if x % 2 == 0: x = x/2 else: x = 3 * x + 1 if x == 1: return x def mathprob(x): string = str(x) print string+"!!!!!!!!!!!!!!!!! This is the starting number!" while x != 1: if x % 2 == 0: x = x/2 print x else: x = 3 * x + 1 print x if x == 1: return x def math_repeat(x,p): while x <= p: mathprob (x) x = x + 1 if mathprob_no_print(x) != 1: print "****YAY****YAY****WE PROVED HIS CONJECTURE WRONG!!!!!!!!!!" math_repeat(1,100)