You've already forked advent_of_code
feat: Redo of the AoC repo starting over with 2015 and keeping up with
2025 (completed day 2 so far)
This commit is contained in:
BIN
15/4/__pycache__/main.cpython-313.pyc
Normal file
BIN
15/4/__pycache__/main.cpython-313.pyc
Normal file
Binary file not shown.
BIN
15/4/__pycache__/test_main.cpython-313-pytest-9.0.1.pyc
Normal file
BIN
15/4/__pycache__/test_main.cpython-313-pytest-9.0.1.pyc
Normal file
Binary file not shown.
26
15/4/main.py
Normal file
26
15/4/main.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import hashlib
|
||||
|
||||
def search_hashes(secret: str, match_str: str) -> int:
|
||||
num = 1
|
||||
|
||||
while True:
|
||||
search_string_bytes = (secret + str(num)).encode()
|
||||
|
||||
hash_string = hashlib.md5(search_string_bytes).hexdigest()
|
||||
|
||||
if hash_string.startswith(match_str):
|
||||
return num
|
||||
|
||||
num += 1
|
||||
|
||||
|
||||
def main():
|
||||
num = search_hashes('ckczppom', '00000')
|
||||
print(f'Part1: {num}')
|
||||
|
||||
num = search_hashes('ckczppom', '000000')
|
||||
print(f'Part2: {num}')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
11
15/4/test_main.py
Normal file
11
15/4/test_main.py
Normal file
@@ -0,0 +1,11 @@
|
||||
import pytest
|
||||
|
||||
from main import search_hashes
|
||||
|
||||
@pytest.mark.parametrize('given, match, expected',
|
||||
[
|
||||
('abcdef', '00000', 609043),
|
||||
('pqrstuv', '00000', 1048970)
|
||||
])
|
||||
def test_searching(given, match, expected):
|
||||
assert search_hashes(given, match) == expected
|
||||
Reference in New Issue
Block a user