From b46027ca9e41acf2a0d8b41d45ad06886c1cf335 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 21 May 2025 00:59:37 +0100 Subject: [PATCH] 2015: d04: ex2: add solution --- 2015/d04/ex2/ex2.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 2015/d04/ex2/ex2.py diff --git a/2015/d04/ex2/ex2.py b/2015/d04/ex2/ex2.py new file mode 100755 index 0000000..8ec99f7 --- /dev/null +++ b/2015/d04/ex2/ex2.py @@ -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()