-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2fca79c
commit 10d0d28
Showing
3 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import hashlib | ||
|
||
|
||
def part_1(raw_input: str) -> int: | ||
return find_with("00000", raw_input) | ||
|
||
|
||
def part_2(raw_input: str) -> int: | ||
return find_with("000000", raw_input) | ||
|
||
|
||
def find_with(prefix: str, raw_input: str) -> int: | ||
number = 1 | ||
|
||
while True: | ||
result = hashlib.md5(str.encode(f'{raw_input}{number}')).hexdigest() | ||
|
||
if result.startswith(prefix): | ||
return number | ||
|
||
number = number + 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import pytest | ||
|
||
from solutions.day4.solution import part_1, part_2 | ||
|
||
|
||
@pytest.mark.parametrize("test_input,expected", [("abcdef", 609043), ("pqrstuv", 1048970)]) | ||
def test_part_1_examples(test_input, expected): | ||
assert part_1(test_input) == expected, f'Should be [{expected}] from [{test_input}]' | ||
|
||
|
||
def test_part_1(): | ||
assert part_1("ckczppom") == 117946 | ||
|
||
|
||
def test_part_2(): | ||
assert part_2("ckczppom") == 3938038 |