Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e7b61a9

Browse filesBrowse files
committed
Add day 14
1 parent 9dc411c commit e7b61a9
Copy full SHA for e7b61a9

File tree

1 file changed

+12
-79
lines changed
Filter options

1 file changed

+12
-79
lines changed

‎2024/14/14.py

Copy file name to clipboard
+12-79Lines changed: 12 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,21 @@
1-
from collections import *
2-
import time
3-
from itertools import *
4-
from functools import *
5-
# import networkx as nx
61
import re
7-
import sys
8-
sys.setrecursionlimit(1000000)
92

10-
s1 = s2 = 0
11-
# coords = {x+1j*y: c for y, r in enumerate(open(0)) for x, c in enumerate(r.strip())}
3+
X, Y = 101, 103
4+
nums = [list(map(int, re.findall(r"-?\d+", line))) for line in open(0)]
125

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 = {}
6+
for i in range(X * Y):
397
quadrant = [0, 0, 0, 0]
40-
nines = [0] * 9
41-
rows = Counter()
42-
for x, y, vx, vy in maps:
8+
picture = [" "] * (X * Y)
9+
for x, y, vx, vy in nums:
4310
nx = (x + vx * i) % X
4411
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))
12+
picture[ny * X + nx] = "#"
13+
if nx != X//2 and ny != Y//2:
14+
quadrant[(nx > X//2) + (ny > Y//2) * 2] += 1
6015

16+
if i == 100:
17+
print(quadrant[0] * quadrant[1] * quadrant[2] * quadrant[3])
6118

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)
19+
if ("#" * 20) in ''.join(picture):
7820
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")
21+
break

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.