2015: d04: ex2: add solution
This commit is contained in:
parent
5eda64047c
commit
b46027ca9e
1 changed files with 23 additions and 0 deletions
23
2015/d04/ex2/ex2.py
Executable file
23
2015/d04/ex2/ex2.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("000000"):
|
||||
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