aboutsummaryrefslogtreecommitdiffstats
path: root/ee2301/collatz.py
blob: 5f50ccc48ec458b9a88fbf780d64a8f8f5cbbbd5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
def collatzCount(k):
    for n in range (1,k+1):
        collatzConjecture(n)
        print("\n")

def collatzConjecture(n):
    print(n, end = ' ')
    if n is 1:
        return 1
    elif n > 1:
        if n%2:
            return collatzConjecture(int((n*3)+1))
        else:
            return collatzConjecture(int(n/2))
    raise AssertionError


try:
    collatzCount(100000)
except AssertionError:
    print("The Collatz Conjecture is false!")