Skip to content

Instantly share code, notes, and snippets.

@qubard
Last active December 14, 2024 05:28
Show Gist options
  • Select an option

  • Save qubard/5094adee7cd6f4e4dc261b5785f34502 to your computer and use it in GitHub Desktop.

Select an option

Save qubard/5094adee7cd6f4e4dc261b5785f34502 to your computer and use it in GitHub Desktop.
Aoc Day 14 Pt 2.py
import re
from copy import deepcopy,copy
from collections import defaultdict, deque
#import networkx as nx
def ints(s):
return [int(match) for match in re.findall(r'-?\d+', s)]
def n3(P):
# includes P in a 3x3
A = []
for i in range(-1,2):
for j in range(-1,2):
if (P[0]+i,P[1]+j) != P:
A.append((P[0]+i,P[1]+j))
return A
def extract_digits(statement):
# Regular expression to match digits inside mul() parentheses
pattern = r'mul\((\d+),(\d+)\)'
match = re.findall(pattern, statement)
return match
def n2(P):
r,c = P
return [(r+1,c),(r-1,c),(r,c-1),(r,c+1)]
# READ FILE
FILENAME = "A"
f = open(FILENAME).readlines()
f = [x.strip() for x in f]
G = defaultdict()
pos = []
for l in f:
x,y,vx,vy = ints(l)
pos.append((x,y,vx,vy))
t = 0
while t < 100000000:
tmp = []
V=set()
for p in pos:
x,y,vx,vy = p
# 101 wide
# 103 tall careful, GRID IS NOT SQUARE
xx = (x+vx)%101
yy = (y+vy)%103
tmp.append((xx,yy,vx,vy))
V.add((xx,yy))
pos = tmp
s = ""
A = set(pos)
adj = 0
for p in V:
if (p[0]+1,p[1]) in V or (p[0]-1,p[1]) in V:
adj += 1
if adj >= len(pos)/3:
for r in range(0,101):
s = ""
for c in range(0,103):
if (r,c) in V:
s += "*"
else:
s += "."
print(s)
print("ELAPSED",t+1)
assert(False)
print("ELAPSED",t+1)
t += 1
quads = defaultdict(int)
x=0
for p in pos:
if p[0] != 50 and p[1] != 51:
quads[(p[0]//(51),p[1]//(52))] += 1
x+=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment