advent-of-code/2015/python/day04.py

32 lines
464 B
Python
Raw Permalink Normal View History

2022-12-09 21:41:14 +00:00
import hashlib
def hsh(st, ct=5):
return hashlib.md5(st.encode('utf-8')).hexdigest()[:ct] == ("0"*ct)
def pt1(seed):
idx = 0
while True:
idx +=1
if hsh(f"{seed}{idx}"):
break
print(idx)
def pt2(seed):
idx = 0
while True:
idx +=1
if hsh(f"{seed}{idx}", 6):
break
print(idx)
def main():
inp = "iwrupvqb"
pt1(inp)
pt2(inp)
if __name__ == "__main__":
main()