#!/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()