2015: d04: ex1: add solution

This commit is contained in:
Bruno BELANYI 2025-05-21 00:59:17 +01:00
parent 6dcb0c3c3b
commit b364263838

23
2015/d04/ex1/ex1.py Executable file
View file

@ -0,0 +1,23 @@
#!/usr/bin/env python
import hashlib
import itertools
import sys
def solve(input: str) -> int:
key = input.strip()
for i in itertools.count(1):
hash = hashlib.md5((key + str(i)).encode()).hexdigest()
if hash.startswith("00000"):
return i
assert False # Sanity check
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()