File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ from collections import defaultdict
2
+ import numpy as np
3
+
4
+ with open ("input" ) as f :
5
+ ns = list (map (int , f .read ().strip ().split ("\n " )))
6
+
7
+
8
+ def hsh (secret ):
9
+ for _ in range (2000 ):
10
+ secret ^= secret << 6 & 0xFFFFFF
11
+ secret ^= secret >> 5 & 0xFFFFFF
12
+ secret ^= secret << 11 & 0xFFFFFF
13
+ yield secret
14
+
15
+
16
+ secrets = list (map (list , map (hsh , ns )))
17
+
18
+ # Part 1
19
+ print (sum (s [- 1 ] for s in secrets ))
20
+
21
+ # Part 2
22
+ result = defaultdict (int )
23
+ for n in ns :
24
+ ss = [s % 10 for s in hsh (n )]
25
+ diffs = np .diff (ss )
26
+ changes = set ()
27
+ for i in range (1996 ):
28
+ if (change := tuple (diffs [i : i + 4 ])) not in changes :
29
+ changes .add (change )
30
+ result [change ] += ss [i + 4 ]
31
+
32
+ print (max (result .values ()))
You can’t perform that action at this time.
0 commit comments