2015: d04: ex1: add solution
This commit is contained in:
parent
6dcb0c3c3b
commit
b364263838
1 changed files with 23 additions and 0 deletions
23
2015/d04/ex1/ex1.py
Executable file
23
2015/d04/ex1/ex1.py
Executable 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()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue