Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 295e247

Browse files
committed
Day 05: Solution of part 2
1 parent 005a089 commit 295e247

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

‎05/log.txt‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ Given the actual Door ID, what is the password?
1717

1818
Your puzzle answer was 2414bc77.
1919

20-
The first half of this puzzle is complete! It provides one gold star: *
21-
2220
--- Part Two ---
2321

2422
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.
@@ -36,4 +34,6 @@ You almost choke on your popcorn as the final character falls into place, produc
3634

3735
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.
3836

39-
Your puzzle input is still wtnhxymk.
37+
Your puzzle answer was 437e60fc.
38+
39+
Both parts of this puzzle are complete! They provide two gold stars: **

‎05/solution.py‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,39 @@
55
class Solution(solution.Solution):
66
def __init__(self, nr):
77
super().__init__(nr)
8-
self.password = ""
8+
self.password1 = ""
9+
self.password2 = list("--------")
910

1011
def calculate(self, test=False):
1112
self.read_instructions()
1213

1314
def read_instructions(self):
1415
self.read_input()
15-
self.calc_password()
16-
self.set_solution(1, self.password)
16+
self.calc_passwords()
1717

18-
def calc_password(self):
18+
def calc_passwords(self):
19+
pos1 = 0
20+
calced2 = 0
1921
index = -1
2022
m = hashlib.md5()
2123
m.update(self.input.encode('utf-8'))
22-
foriinrange(0, 8):
24+
whilenotself.is_calculated(1) ornotself.is_calculated(2):
2325
while True:
2426
index += 1
2527
mc = m.copy()
2628
mc.update(str(index).encode('utf-8'))
2729
md5 = mc.hexdigest()
2830
if md5[:5] == "00000":
29-
self.password += md5[5]
31+
if not self.is_calculated(1):
32+
self.password1 += md5[5]
33+
pos1 += 1
34+
if pos1 > 7:
35+
self.set_solution(1, self.password1)
36+
if not self.is_calculated(2):
37+
if md5[5].isdigit() and -1 < int(md5[5]) < 8:
38+
if self.password2[int(md5[5])] == "-":
39+
self.password2[int(md5[5])] = md5[6]
40+
calced2 += 1
41+
if calced2 > 7:
42+
self.set_solution(2, "".join(self.password2))
3043
break

‎05/test.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ def test_1(self):
1010
test_input = "abc"
1111
self.execute_test(test_input)
1212
self.assertEqual("18f47a30", self.solution.get_solution(1))
13+
self.assertEqual("05ace8e3", self.solution.get_solution(2))

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /