Skip to content

Commit 005a089

Browse files
committed
Day 05: Solution of part 1
1 parent 6f2f378 commit 005a089

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

05/log.txt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,25 @@ In this example, after continuing this search a total of eight times, the passwo
1515

1616
Given the actual Door ID, what is the password?
1717

18-
Your puzzle input is wtnhxymk.
18+
Your puzzle answer was 2414bc77.
19+
20+
The first half of this puzzle is complete! It provides one gold star: *
21+
22+
--- Part Two ---
23+
24+
As the door slides open, you are presented with a second door that uses a slightly more inspired security mechanism. Clearly unimpressed by the last version (in what movie is the password decrypted in order?!), the Easter Bunny engineers have worked out a better solution.
25+
26+
Instead of simply filling in the password from left to right, the hash now also indicates the position within the password to fill. You still look for hashes that begin with five zeroes; however, now, the sixth character represents the position (0-7), and the seventh character is the character to put in that position.
27+
28+
A hash result of 000001f means that f is the second character in the password. Use only the first result for each position, and ignore invalid positions.
29+
30+
For example, if the Door ID is abc:
31+
32+
The first interesting hash is from abc3231929, which produces 0000015...; so, 5 goes in position 1: _5______.
33+
In the previous method, 5017308 produced an interesting hash; however, it is ignored, because it specifies an invalid position (8).
34+
The second interesting hash is at index 5357525, which produces 000004e...; so, e goes in position 4: _5__e___.
35+
You almost choke on your popcorn as the final character falls into place, producing the password 05ace8e3.
36+
37+
Given the actual Door ID and this new method, what is the password? Be extra proud of your solution if it uses a cinematic "decrypting" animation.
38+
39+
Your puzzle input is still wtnhxymk.

05/solution.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
11
from lib import solution
2+
import hashlib
23

34

45
class Solution(solution.Solution):
56
def __init__(self, nr):
67
super().__init__(nr)
8+
self.password = ""
79

810
def calculate(self, test=False):
911
self.read_instructions()
1012

1113
def read_instructions(self):
1214
self.read_input()
15+
self.calc_password()
16+
self.set_solution(1, self.password)
17+
18+
def calc_password(self):
19+
index = -1
20+
m = hashlib.md5()
21+
m.update(self.input.encode('utf-8'))
22+
for i in range(0, 8):
23+
while True:
24+
index += 1
25+
mc = m.copy()
26+
mc.update(str(index).encode('utf-8'))
27+
md5 = mc.hexdigest()
28+
if md5[:5] == "00000":
29+
self.password += md5[5]
30+
break

0 commit comments

Comments
 (0)