Skip to content

Commit 258364d

Browse files
committed
Add day 22
1 parent 1d05697 commit 258364d

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

2024/22/22.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
1-
from collections import Counter
2-
3-
s1 = [0]
4-
5-
def secret(num):
6-
prices = Counter()
7-
last4 = (10,10,10,10)
8-
for i in range(2000):
1+
s1, s2 = 0, {}
2+
for num in map(int, open(0)):
3+
seen = set()
4+
last4 = (10, 10, 10, 10)
5+
for _ in range(2000):
96
prev = num%10
107
num ^= (num*64) % 16777216
11-
num ^= (num//32) % 16777216
8+
num ^= num//32
129
num ^= (num*2048) % 16777216
1310
last4 = last4[1:] + (num%10 - prev,)
14-
if last4 not in prices:
15-
prices[last4] = num%10
16-
s1[0] += num
17-
return prices
11+
if last4 not in seen:
12+
seen.add(last4)
13+
s2[last4] = s2.get(last4, 0) + num%10
14+
s1 += num
1815

19-
ints = map(int, open(0))
20-
c = sum(map(secret, ints), Counter())
21-
print(s1[0])
22-
print(sorted(c.values())[-1])
16+
print(s1)
17+
print(sorted(s2.values())[-1])

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy