Skip to content

Commit 021d01b

Browse files
committed
Add day 22
1 parent b362d3a commit 021d01b

File tree

3 files changed

+78
-2
lines changed

3 files changed

+78
-2
lines changed

.aoc_tiles/tiles/2024/22.png

8.26 KB
Loading

2024/22/22.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
from collections import *
2+
from itertools import *
3+
from functools import *
4+
import numpy as np
5+
import networkx as nx
6+
# import z3
7+
import re
8+
import sys
9+
sys.setrecursionlimit(1000000)
10+
11+
s1 = s2 = 0
12+
# coords = {x+1j*y: c for y, r in enumerate(open(0)) for x, c in enumerate(r.strip())}
13+
14+
d4 = [1, 1j, -1, -1j]
15+
d8 = d4 + [1+1j, 1-1j, -1+1j, -1-1j]
16+
d4half = [i/2 for i in d4]
17+
d8half = [i/2 for i in d8]
18+
def adjacent(coord, dirs=d4):
19+
return [coord + d for d in dirs]
20+
21+
# G = nx.Graph()
22+
# for c in coords:
23+
# for d in [1, 1j, -1, -1j]:
24+
# if coords[c] != '#' != coords[c+d]:
25+
# G.add_edge(c, c+d)
26+
27+
# S = [c for c in coords if coords[c] in 'S'][0]
28+
# coord_to_dist = nx.shortest_path_length(G, S).items()
29+
30+
31+
# Calculate the result of multiplying the secret number by 64. Then, mix this result into the secret number. Finally, prune the secret number.
32+
# Calculate the result of dividing the secret number by 32. Round the result down to the nearest integer. Then, mix this result into the secret number. Finally, prune the secret number.
33+
# Calculate the result of multiplying the secret number by 2048. Then, mix this result into the secret number. Finally, prune the secret number.
34+
35+
def secret(num):
36+
mod10 = []
37+
price = []
38+
print(num)
39+
for i in range(2000):
40+
prev = num
41+
num ^= num * 64
42+
num %= 16777216
43+
num ^= num // 32
44+
num %= 16777216
45+
num ^= num * 2048
46+
num %= 16777216
47+
mod10.append((num%10 - prev%10))
48+
price.append(num%10)
49+
# print(f"{num} {num%10=} {num%10-prev%10=}")
50+
return mod10, price
51+
52+
53+
c = Counter()
54+
for line in open(0):
55+
n = int(line)
56+
# s1 += secret(n)
57+
a, price = secret(n)
58+
# print(a[:20])
59+
# print(price[:20])
60+
seen = set()
61+
for i, (t, p) in enumerate(zip(zip(a, a[1:], a[2:], a[3:]), price[3:])):
62+
if t not in seen:
63+
seen.add(t)
64+
c[t] += p
65+
# exit()
66+
print(c.most_common(20))
67+
print(c[(-2,1,-1,3)])
68+
69+
70+
# re.findall(r"\d+", line)
71+
72+
73+
print(s1, s2, sep="\n")

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<!-- AOC TILES BEGIN -->
22
<h1 align="center">
3-
Advent of Code - 252/492
3+
Advent of Code - 254/494
44
</h1>
55
<h1 align="center">
6-
2024 - 42 ⭐ - Python
6+
2024 - 44 ⭐ - Python
77
</h1>
88
<a href="2024/01/01.py">
99
<img src=".aoc_tiles/tiles/2024/01.png" width="161px">
@@ -68,6 +68,9 @@
6868
<a href="2024/21/21.py">
6969
<img src=".aoc_tiles/tiles/2024/21.png" width="161px">
7070
</a>
71+
<a href="2024/22/22.py">
72+
<img src=".aoc_tiles/tiles/2024/22.png" width="161px">
73+
</a>
7174
<h1 align="center">
7275
2023 - 50 ⭐ - Python
7376
</h1>

0 commit comments

Comments
 (0)