summaryrefslogtreecommitdiff
path: root/04/main.py
blob: 1014062cab2e97602e23ae504b1732f838727190 (plain)
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
#!/usr/bin/python

from hashlib import md5



def solve_partn(partn, key):
    if partn == 1:
        prefix = "00000"
    else: # partn == 2
        prefix = "000000"

    n = 0
    h = "undefined"
    while not h.startswith(prefix):
        n += 1
        d = key + str(n)
        h = md5(d.encode()).hexdigest()
    return n



def main():
    # My personal input string
    key = "ckczppom"

    print("Part 1 solution:", solve_partn(1, key)) #  117946 for me
    print("Part 2 solution:", solve_partn(2, key)) # 3938038 for me



if __name__ == "__main__":
    main()