AdventOfCode/2015/04/solution.py

74 lines
1.9 KiB
Python
Raw Normal View History

2024-11-28 19:53:47 +01:00
#!/bin/python3
import sys,re,hashlib
from pprint import pprint
sys.path.insert(0, '../../')
from fred import list2int
input_f = 'input'
part = 2
#########################################
# #
# Part 1 #
# #
#########################################
if part == 1:
result = 0
count = 0
found = False
with open(input_f) as file:
for line in file:
tmp = line.rstrip()
while found == False:
m = hashlib.md5()
text = tmp + str(count)
#print(text)
m.update(text.encode('UTF-8'))
nr = m.hexdigest()
#print(nr)
if nr[0:5] == '00000':
print(count)
#print(text)
#print(nr)
found = True
else:
count += 1
#print(nr[ 0 : 5 ])
found = False
#########################################
# #
# Part 2 #
# #
#########################################
if part == 2:
result = 0
count = 0
found = False
with open(input_f) as file:
for line in file:
tmp = line.rstrip()
while found == False:
m = hashlib.md5()
text = tmp + str(count)
#print(text)
m.update(text.encode('UTF-8'))
nr = m.hexdigest()
#print(nr)
if nr[0:6] == '000000':
print(count)
#print(text)
#print(nr)
found = True
else:
count += 1
#print(nr[ 0 : 5 ])
found = False