2016: d05: ex1: add solution
This commit is contained in:
parent
e306d68e81
commit
25dbce3ee2
1 changed files with 29 additions and 0 deletions
29
2016/d05/ex1/ex1.py
Executable file
29
2016/d05/ex1/ex1.py
Executable file
|
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import hashlib
|
||||
import itertools
|
||||
import sys
|
||||
|
||||
|
||||
def solve(input: str) -> str:
|
||||
def crack_password(door_id: str) -> str:
|
||||
password: list[str] = []
|
||||
for i in itertools.count():
|
||||
hash = hashlib.md5((door_id + str(i)).encode()).hexdigest()
|
||||
if not hash.startswith("00000"):
|
||||
continue
|
||||
password.append(hash[5])
|
||||
if len(password) == 8:
|
||||
break
|
||||
return "".join(password)
|
||||
|
||||
return crack_password(input.strip())
|
||||
|
||||
|
||||
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