Skip to content

Commit 9dc411c

Browse files
committed
Add day 14
1 parent 28887aa commit 9dc411c

File tree

3 files changed

+93
-2
lines changed

3 files changed

+93
-2
lines changed

Diff for: .aoc_tiles/tiles/2024/14.png

8.09 KB
Loading

Diff for: 2024/14/14.py

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
from collections import *
2+
import time
3+
from itertools import *
4+
from functools import *
5+
# import networkx as nx
6+
import re
7+
import sys
8+
sys.setrecursionlimit(1000000)
9+
10+
s1 = s2 = 0
11+
# coords = {x+1j*y: c for y, r in enumerate(open(0)) for x, c in enumerate(r.strip())}
12+
13+
d4 = [1, 1j, -1, -1j]
14+
d8 = d4 + [1+1j, 1-1j, -1+1j, -1-1j]
15+
d4half = [i/2 for i in d4]
16+
d8half = [i/2 for i in d8]
17+
def adjacent(coord, dirs=d4):
18+
return [coord + d for d in dirs]
19+
20+
21+
22+
23+
X = 101
24+
Y = 103
25+
# X = 11
26+
# Y = 7
27+
maps = []
28+
for line in open(0):
29+
x, y, vx, vy = map(int, re.findall(r"-?\d+", line))
30+
maps.append((x, y, vx, vy))
31+
8
32+
70
33+
284
34+
35+
seen = set()
36+
37+
for i in range(0, X * Y, 1):
38+
counts = {}
39+
quadrant = [0, 0, 0, 0]
40+
nines = [0] * 9
41+
rows = Counter()
42+
for x, y, vx, vy in maps:
43+
nx = (x + vx * i) % X
44+
ny = (y + vy * i) % Y
45+
if (nx, ny) not in counts:
46+
counts[(nx, ny)] = 0
47+
counts[(nx, ny)] += 1
48+
rows[ny] += 1
49+
# print(x, y, nx, ny)
50+
# print(nx, (nx >= 55) + (ny >= 56) * 2)
51+
# print(X // 2, Y // 2)
52+
if nx != X // 2 and ny != Y // 2:
53+
q = (nx > X//2) + (ny > Y//2) * 2
54+
#print(q)
55+
quadrant[q] += 1
56+
n = (nx // (X//3+1)) + (ny // (Y//3+1)) * 3
57+
# print(n)
58+
nines[n] += 1
59+
seen.add((tuple(sorted(quadrant)), i))
60+
61+
62+
# key = tuple(counts.items())
63+
# if key in seen:
64+
# break
65+
# seen.add(key)
66+
67+
s = quadrant[0] * quadrant[1] * quadrant[2] * quadrant[3]
68+
# if any(q <= 10 for q in nines):
69+
if rows[40] > 30:
70+
for yy in range(Y):
71+
print(end=str(yy))
72+
for xx in range(X):
73+
print(end="#" if (xx, yy) in counts else " ")
74+
# print(end=str(counts.get((xx, yy), " ")))
75+
print()
76+
77+
print(quadrant)
78+
print(i)
79+
print()
80+
# time.sleep(0.1)
81+
82+
# print(quadrant)
83+
84+
# print(sorted(seen, reverse=True))
85+
86+
print(quadrant)
87+
88+
print(s1, s2, sep="\n")

Diff for: README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<!-- AOC TILES BEGIN -->
22
<h1 align="center">
3-
Advent of Code - 236/476
3+
Advent of Code - 238/478
44
</h1>
55
<h1 align="center">
6-
2024 - 26 ⭐ - Python
6+
2024 - 28 ⭐ - Python
77
</h1>
88
<a href="2024/01/01.py">
99
<img src=".aoc_tiles/tiles/2024/01.png" width="161px">
@@ -44,6 +44,9 @@
4444
<a href="2024/13/13.py">
4545
<img src=".aoc_tiles/tiles/2024/13.png" width="161px">
4646
</a>
47+
<a href="2024/14/14.py">
48+
<img src=".aoc_tiles/tiles/2024/14.png" width="161px">
49+
</a>
4750
<h1 align="center">
4851
2023 - 50 ⭐ - Python
4952
</h1>

0 commit comments

Comments
 (0)