File tree Expand file tree Collapse file tree 4 files changed +43
-1
lines changed Expand file tree Collapse file tree 4 files changed +43
-1
lines changed Original file line number Diff line number Diff line change
1
+ 1a3099aa
2
+ 694190cd
Original file line number Diff line number Diff line change
1
+ uqwqemis
Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env python3
2
+
3
+ def load_data (filename ):
4
+ with open (filename , 'r' ) as f :
5
+ line = f .readline ().rstrip ('\n ' )
6
+ return line
7
+
8
+ # Part One
9
+
10
+ door_id = load_data ('input.txt' )
11
+
12
+ from hashlib import md5
13
+
14
+ index = 0
15
+ result = ''
16
+
17
+ for _ in range (8 ):
18
+ while not (hash := md5 ((door_id + str (index )).encode ('ascii' )).hexdigest ()).startswith ('00000' ):
19
+ index += 1
20
+ index += 1
21
+ result += hash [5 ]
22
+
23
+ print (result )
24
+
25
+ # Part Two
26
+
27
+ index = 0
28
+ result = list ('_' * 8 )
29
+
30
+ while '_' in result :
31
+ while not (hash := md5 ((door_id + str (index )).encode ('ascii' )).hexdigest ()).startswith ('00000' ):
32
+ index += 1
33
+ index += 1
34
+ i = int (hash [5 ], 16 )
35
+ if i >= len (result ) or result [i ] != '_' :
36
+ continue
37
+ result [i ] = hash [6 ]
38
+
39
+ print ('' .join (result ))
Original file line number Diff line number Diff line change 1
1
```
2
2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
3
3
2015 ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +
4
- 2016 ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
4
+ 2016 ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
5
5
2017 ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
6
6
2018 ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +
7
7
2019 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- ++ ++ -- +- ++ +- -
You can’t perform that action at this time.
0 commit comments