#AoC 2023 | Code Golfing
2369 messages Β· Page 3 of 3 (latest)
[Day 11] 242 ```py
I,=open(0)
R=range
for q in 2,106:
*G,D=0,
for i in R(140):
for j in R(140):
if'.'>I[i][j]:
for a,b in G:D+=sum(qall(l[x]>'#'for l in I)for x in R(sorted([a,j])))+sum(q-~-('#'in I[y])for y in R(b,i))
G+=(j,i),
print(D)
oop
I hate websockets
[Day 11] 237 ```py
I,=open(0)
R=range
for q in 2,106:
*G,D=0,
for i in R(140):
for j in R(140):
if'.'>I[i][j]:D+=sum(sum(qall(l[x]>'#'for l in I)for x in R(sorted([a,j])))+sum(q-~-('#'in I[y])for y in R(b,i))for a,b in G);G+=(j,i),
print(D)
Someone submitted a 234 lol
[Day 11] 234
*k,=open(t:=0)
for c in 2,10**6:r,s=[[t:=t+[1,c][all(c!="#"for c in l)] for l in arr]for arr in(zip(*k),k)];e=[(x,y)for l,y in zip(k,s)for c,x in zip(l,r)if c=="#"];print(sum(abs(a[0]-b[0])+abs(a[1]-b[1])for a in e for b in e if a<b))
(submitted by livingboxy)
and it runs fast enough to not trip whatever error ATO is throwing at me
oh damn
[Day 11] 229 not any more it doesn't :P
*k,=open(t:=0)
for c in 2,10**6:r,s=[[t:=t+[1,c][all(c!="#"for c in l)]for l in R]for R in(zip(*k),k)];e=[(x,y)for l,y in zip(k,s)for c,x in zip(l,r)if c=="#"];print(sum(abs(a[0]-b[0])+abs(a[1]-b[1])for a in e for b in e if a<b))
[Day 11] 224 ```py
k,=open(t:=0)
for c in 2,10**6:r,s=[[t:=t+(1|call(c<'.'for c in l))for l in A]for A in(zip(*k),k)];e=[(x,y)for l,y in zip(k,s)for c,x in zip(l,r)if'.'>c];print(sum(abs(x-u)+abs(y-v)for x,y in e for u,v in e if(x,y)<(u,v)))
nvm
disqualify that
[Day 11] 228
*k,=open(t:=0)
for c in 2,10**6:r,s=[[t:=t+[1,c][all(c!="#"for c in l)]for l in R]for R in(zip(*k),k)];e=[(x,y)for l,y in zip(k,s)for c,x in zip(l,r)if'#'==c];print(sum(abs(a[0]-b[0])+abs(a[1]-b[1])for a in e for b in e if a<b))
[Day 11] 224
*k,=open(t:=0)
for c in 2,10**6:r,s=[[t:=t+c**all(c!="#"for c in l)for l in R]for R in(zip(*k),k)];e=[(x,y)for l,y in zip(k,s)for c,x in zip(l,r)if'#'==c];print(sum(abs(a[0]-b[0])+abs(a[1]-b[1])for a in e for b in e if a<b))
[Day 11] 222 ```py
*k,=open(t:=0)
for c in 2,106:r,s=[[t:=t+call(c!="#"for c in l)for l in R]for R in(zip(*k),k)];e=[(x,y)for l,y in zip(k,s)for c,x in zip(l,r)if'.'>c];print(sum(abs(x-u)+abs(y-v)for x,y in e for u,v in e if(x,y)<(u,v)))
I swear I tried that lol
Oh, damnit, I switched the wrong one back first
[Day 11] 217
*k,=open(t:=0)
for c in 2,10**6:r,s=[[t:=t+c**all(c!="#"for c in l)for l in R]for R in(zip(*k),k)];e=[(x,y)for l,y in zip(k,s)for c,x in zip(l,r)if'.'>c];print(sum(u-x+abs(y-v)for x,y in e for u,v in e if(x,y)<(u,v)))
surely there must be a way to make the r,s= and e= comprehensions work together in a non-zip() way
Β―_(γ)_/Β―
...why did this ever work, '\n'<'.' lol
We now have an actual counter-example and I've fixed history to add the correct version
OH
There was a trailing newline in their input
π€¦
[Day 11] 212
*k,=open(t:=0)
for c in 2,10**6:r,s=[[t:=t+c**all(c!="#"for c in l)for l in R]for R in(zip(*k),k)];e=[(x,y)for l,y in zip(k,s)for c,x in zip(l,r)if'.'>c];print(sum(max(0,u-x)+max(0,y-v)for x,y in e for u,v in e))
can't you just use sum. instead of t here?
...no? It's a 2 item comprehension that's later getting unpacked
2 items?
just the value of c**all(c!="#"for c in l) is added to t each loop cycle
And it's unpacked into r and s
Wait I transposed the loop lol
It's two lists that are unpacked into r and s and are then used for iteration later
modified a solution on reddit to get a 217. hope it somehow helps
[Day 11] 217
*w,=open(0)
for i in 2,10**6:print(sum(map(lambda q:(q:=[sum(p in q or i for p in range(p))
for p in q])and sum(abs(a-b)for a in q for b in q),zip(*[(x,y)for
y,r in enumerate(w)for x,c in enumerate(r)if c=='#'])))//2)```
is that map(lambda ...) not longer than a genexpr
also assign enumerate to something
oh wow it works
[Day 11] 208 ```py
w,=open(0);R=range(140)
for i in 2,10**6:print(sum((Q:=[sum(p in q or i for p in range(p))for p in q])and sum(abs(a-b)for a in Q for b in Q)for q in zip([(x,y)for y in R for x in R if'.'>w[y][x]]))//2)
[Day 11] 203 ```py
w,=open(0);R=range;T=R(140)
for i in 2,10**6:print(sum((Q:=[sum(p in q or i for p in R(p))for p in q])and sum(abs(a-b)for a in Q for b in Q)for q in zip([(x,y)for y in T for x in T if'.'>w[y][x]]))//2)
[Day 11] 144 from cg server ```py
k,=open(t:=0)
for p in 2,10*6:
u=0
for R in(zip(k),k):
o=0;s=0
for l in R:c=l.count("#");t+=p(c<1);u+=c(to-s);o+=c;s+=ct
print(u)
[Day 11] 143
*k,=open(t:=0)
for p in 2,10**6:
u=0
for R in zip(*k),k:
o=0;s=0
for l in R:c=l.count("#");t+=p**(c<1);u+=c*(t*o-s);o+=c;s+=c*t
print(u)
we're on 141 in cg server btw
[Day 11] 136 back with good ol' exec() ```py
k=open(t:=0)
for p in 2,10**6:u=0;exec('\no=s=0;k,=zip(k)\nfor l in k:c=l.count("#");t+=p(c<1);u+=c*(to-s);o+=c;s+=ct'*2);print(u)
[Day 11] 124
a=open(0)
for f in 1,999999:s=0;exec("\nu=d=0;*a,=zip(*a)\nfor l in a:c=l.count('#');s+=d*c;u+=c;d+=u+u*f*(c<1)"*2);print(s)```
credits : boxy, magnus, crow, stickie and plenty others from the cg discord
[Day 11] 122 from cg server ```py
a=open(0)
for f in 2,106:s=0;exec("\nu=d=0;a,=zip(a)\nfor l in a:c=l.count('#');s+=dc;u+=c;d+=uf(c<1)"*2);print(s)
[Day 11] 121 from cg server
a=open(0)
for f in 2,10**6:s=0;exec("\nu=d=0;*a,=zip(*a)\nfor l in a:c=l.count('#');s+=d*c;u+=c;d+=u*f**0**c"*2);print(s)```
https://www.reddit.com/r/adventofcode/comments/18ft8fo/advent_of_code_golf_2023_join_the_challenge/
put up a reddit post for it. All upvotes are welcome.
who's doing the initial golf for today?
[Day 12] 268
from functools import*
C=cache(lambda l,r:r and(c:=r[0])and~sum(~C(l[i-~c:],r[1:])for i in range(len(l)-c+1)if{'#'}-{l[i+c:i-~c],*l[:i]}and{'.'}-{*l[i:i+c]})or~('#'not in l))
*i,=open(0)
for n in 1,5:print(sum(~C("?".join([l]*n),eval(r)*n)for l,r in map(str.split,i)))
alternatively, [Day 12] 297
from functools import*
@cache
def t(x,y):
if not x:return"#"not in y
if not y:return 0
h,g=0,x[0]
if("."in y[:g])<(len(y)>=g)*(y[g:g+1]!='#'):h+=t(x[1:],y[g+1:])
if"#"<y[0]:h+=t(x,y[1:])
return h
a=b=0
for l in open(0):s,g=l.split();a+=t(g:=eval(g),s);b+=t(g*5,"?".join([s]*5))
print(a,b)
```from the cg server
current best (264)
from functools import*
C=cache(lambda l,r:r and(c:=r[0])and~sum(~C(l[i-~c:],r[1:])for i in range(len(l)-c+1)if{'#'}-{l[i+c:i-~c],*l[:i]}and{'.'}-{*l[i:i+c]})or~('#'in l)^1)
*i,=open(0)
for n in 1,5:print(sum(~C(l+('?'+l)*~-n,eval(r)*n)for l,r in map(str.split,i)))```
damn
and theoretically golf a length-30 considering that you can just remove the cache and it'l still give a solution at some point
yup
[Day 12] 246
from functools import*
C=cache(lambda l,c=0,*e:c and~sum(~C(l[i-~c:],*e)for i in range(99)if('#'in l[i+c]+l[:i]or'.'in l[i:i+c])<1)or('#'in l)-2)
*i,=open(0)
for n in 1,5:print(sum(~C(l+('?'+l)*~-n+'.'*199,*eval(r)*n)for l,r in map(str.split,i)))```
by ovs on cg discord
16 bytes off sub 200
maybe just keeping a dict is smaller than using fuctools?
Is it really? Try reducing it if you're able to π
i tried but yeah it isnt π
Lol, what is that version looking like tho?
How many bytes longer? π€
i didnt actually write it out
but you need at least
M={}
M.get((l,c,e),{..})
M[(l,c,e)]={..}
which is already more than 30 bytes
and i dont think it would work as a lambda so thatd be bigger too?
@winter prawn
you don't need the parens when indexing the dict
229 bytes
from functools import*
f=cache(lambda s,c=0,*l,b='.':(s.find(b)>=c)*f(s[c:],*l,b='')+(s>'#z')*f(s[1:],c,*l)if(c*s)else s>'#'not in s)
L=*open(0),
for k in 1,5:print(sum(f(s+('?'+s)*~-k+'.',*eval(l)*k)for s,l in map(str.split,L)))```
finally sub 200 from cg server
from functools import*βc=cache(lambda ...:...)
M={}βdef c(...):M[l,c,e]=v=(l,c,e)in M and M[l,c,e]or...;return v
I did, this is what I think the minimum necessary looks like (actual expressions omitted where they'd be identical)
Actually you can probably cheat a little:
from functools import*βc=cache(lambda ...:...)
M={}βdef c(...):M[l,c,e]=v=M.get((l,c,e))or...;return v
(if the cached value is 0 it should be cheap to compute, right?)
[Day 13] 220 just to start off
R=[0]*99
for g in map(str.split,open(0).read().split('\n\n')):
for n,g in[1,g],[100,[*zip(*g)]]:
for i in range(v:=len(g[0])-1):R[sum([r[:i+1][::-1][:(h:=min(i+1,v-i))]!=r[i+1:][:h]for r in g])]+=n*(i+1)
print(*R[:2])
Data should have synced by now, did you submit it?
yup
nope doesn't work for my p2
@cerulean lantern sending tc
can you send it to me too? so i can debug
@winter prawn does the 223 work or do I need to roll that back too
which 223?
Actually I guess I could test that myself now I've added the answer
Presumably in the cg server
the 223 is the same
i just replaced list() with [*]
oh
i think i know whats wrong
i dont actually check if its a different reflection for p2π
wait no that shouldnt matter since i check if exactly 1 character is wrong so that shouldnt happen if its the same
[Day 13] 238
R=[0]*99
for g in map(str.split,open(0).read().split('\n\n')):
for n,g in[1,g],[100,[*zip(*g)]]:
for i in range(v:=len(g[0])-1):h=min(i+1,v-i);R[sum(a!=b for r in g for a,b in zip(r[:i+1][::-1][:h],r[i+1:][:h]))]+=n*(i+1)
print(*R[:2])
i checked if one line was different not one character oops
[Day 13] 203```py
R=[0]99
for G in map(str.split,open(0).read().split('\n\n')):
forg,n in[*G,100],[*zip(*G),1]:
for i in range(len(g)):R[sum(a!=b for r in zip(g[:i][::-1],g[i:])for a,b in zip(r))]+=ni
print(*R[:2])
[Day 13] 200
R=[0]*99
for G in open(0).read().split('\n\n'):
G=G.split()
for g in[*zip(*G)],G:
for i in range(len(g)):R[sum(a!=b for r in zip(g[:i][::-1],g[i:])for a,b in zip(*r))]+=i*100**(G==g)
print(*R[:2])
[day 13] alternative 203 ```py
I=open(0).read()
for N in 0,1:print(sum(i100**(G==g)(sum(a!=b for r in zip(g[:i][::-1],g[i:])for a,b in zip(*r))==N)for G in map(str.split,I.split('\n\n'))for g in([*zip(*G)],G)for i in range(len(g))))
[Day 13] 194 mostly from codegolf server
R=[0]*99
for g in open(0).read().split('\n\n'):
g=g.split()
for n in 1,100:
i=1
while g[0][i:]:R[sum(sum(map(str.__ne__,r[i-1::-1],r[i:]))for r in g)]+=n*i;i+=1
*g,=zip(*g)
print(*R[:2])
[Day 13] 183 from cg server
R=[0]*99
for g in open(0).read().split('\n\n'):g=g.split();exec("00\n*g,=zip(*g);i=0\nwhile K:=[a!=b for r in g for a,b in zip(r[i::-1],r[i+1:])]:i+=1;R[sum(K)]+=i*1"*2)
print(*R[:2])```
[Day 13] 181 ```py
g,R=[0]99,
forl,L inopen(0),'0':g=[g,l]-~-([]==l!=exec("00\n*g,=zip(g);i=0\nwhile K:=[a!=b for r in g for a,b in zip(r[i::-1],r[i+1:])]:i+=1;R[sum(K)]+=i1"*2))
print(*R[:2])
[Day 14] 361
*I,=open(c:=0)
R=range(100)
D={}
S=lambda:print(sum((len(I)-y)*I[y].count('O')for y in R))
while c<1e9:
c+=1
for d in 1,2,3,4:
*I,=map(list,I)
for x in R:
for y in R:
if I[y][x]>'.':
I[y][x]='.'
while y and I[y-1][x]=='.':y-=1
I[y][x]='O'
if c<2>d:S()
*I,=zip(*I[::-1])
s=str(I)
if s in D:d=c-D[s];c+=d*((1e9-c)//d)
D[s]=c
S()
basically just my solution except no variable names but at least its a place to start
Did you validate?
just submitted to bot
[Day 14] 360
*I,=open(c:=0)
R=range(100)
D={}
S=lambda:print(sum((len(I)-y)*I[y].count('O')for y in R))
while c<1e9:
c+=1
for d in 1,2,3,4:
*I,=map(list,I)
for x in R:
for y in R:
if I[y][x]>'.':
I[y][x]='.'
while y and'.'==I[y-1][x]:y-=1
I[y][x]='O'
if c<2>d:S()
*I,=zip(*I[::-1])
s=str(I)
if s in D:d=c-D[s];c+=d*((1e9-c)//d)
D[s]=c
S()
Wait
[Day 14] 359
*I,=open(c:=0)
R=range(100)
D={}
S=lambda:print(sum((len(I)-y)*I[y].count('O')for y in R))
while c<1e9:
c+=1
for d in 1,2,3,4:
*I,=map(list,I)
for x in R:
for y in R:
if'.'<I[y][x]:
I[y][x]='.'
while y and'.'==I[y-1][x]:y-=1
I[y][x]='O'
if c<2>d:S()
*I,=zip(*I[::-1])
s=str(I)
if s in D:d=c-D[s];c+=d*((1e9-c)//d)
D[s]=c
S()
Low hanging fruit π
ah right nvm
[Day 14] 358
*I,=open(c:=0)
R=range(100)
D={}
S=lambda:print(sum((len(I)-y)*I[y].count('O')for y in R))
while c<1e9:
c+=1
for d in 1,2,3,4:
*I,=map(list,I)
for x in R:
for y in R:
if'.'<I[y][x]:
I[y][x]='.'
while'.'==I[y-1][x]and y:y-=1
I[y][x]='O'
if c<2>d:S()
*I,=zip(*I[::-1])
s=str(I)
if s in D:d=c-D[s];c+=d*((1e9-c)//d)
D[s]=c
S()
[Day 14] 356
*I,=open(c:=0)
R=range(100)
D={}
S=lambda:print(sum((len(I)-y)*I[y].count('O')for y in R))
while c<1e9:
c+=1
for d in 1,2,3,4:
*I,=map(list,I)
for x in R:
for y in R:
if'.'<I[y][x]:
I[y][x]='.'
while'.'in I[y-1][x]*y:y-=1
I[y][x]='O'
if c<2>d:S()
*I,=zip(*I[::-1])
s=str(I)
if s in D:d=c-D[s];c+=d*((1e9-c)//d)
D[s]=c
S()
wdym?
Oh wait no we're multiplying the string lol
its alright, its gone now:
[Day 14] 348
*I,=open(c:=0)
R=range(100)
D={}
S=lambda:print(sum((len(I)-y)*I[y].count('O')for y in R))
while c<1e9:
c+=1
for d in 1,2,3,4:
*I,=map(list,I)
for x in R:
p=0
for y in R:
if'.'<I[y][x]:I[y][x]='.';I[p][x]='O';p+=1
if'.'>I[y][x]:p=y+1
if c<2>d:S()
*I,=zip(*I[::-1])
s=str(I)
if s in D:d=c-D[s];c+=d*((1e9-c)//d)
D[s]=c
S()
[Day 14] 347
*I,=open(c:=0)
R=range(100)
D={}
S=lambda:print(sum((len(I)-y)*I[y].count('O')for y in R))
while c<1e9:
for d in 0,1,2,3:
*I,=map(list,I)
for x in R:
p=0
for y in R:
if'.'<I[y][x]:I[y][x]='.';I[p][x]='O';p+=1
if'.'>I[y][x]:p=y+1
if c<1>d:S()
*I,=zip(*I[::-1])
s=str(I);c+=1
if s in D:d=c-D[s];c+=d*((1e9-c)//d)
D[s]=c
S()
It's really annoying me that aliasing range is 1c longer than just not using it lol
[Day 14] 345
*I,=open(c:=0)
R=range(100)
D={}
S=lambda:print(sum((len(I)-y)*I[y].count('O')for y in R))
while c<1e9:
for d in 0,1,2,3:
*I,=map(list,I)
for x in R:
p=0
for y in R:
if'.'<I[y][x]:I[y][x]='.';I[p][x]='O';p+=1
if'.'>I[y][x]:p=y+1
if c<1>d:S()
*I,=zip(*I[::-1])
s=str(I);c+=1
if s in D:d=c-D[s];c+=(1e9-c)//d*d
D[s]=c
S()
[Day 14] 341
*I,=open(c:=0)
R=range(100)
D={}
S=lambda:print(sum((len(I)-y)*I[y].count('O')for y in R))
while c<1e9:
for d in 0,1,2,3:
*I,=map(list,I)
for x in R:
p=0
for y in R:
if'.'<I[y][x]:I[y][x]='.';I[p][x]='O';p+=1
if'.'>I[y][x]:p=y+1
if c<1>d:S()
*I,=zip(*I[::-1])
c+=1;d=c-D.get(s:=str(I),-1e9);c+=(1e9-c)//d*d;D[s]=c
S()
Damn we had the same idea but you did it better
:D
well I submitted first so they're both in the repo history ig
[Day 14] 336
*I,=open(c:=0)
R=range(100)
D={}
S=lambda:print(sum((len(I)-y)*I[y].count('O')for y in R))
while c<1e9:
for d in 0,1,2,3:
*I,=map(list,I)
for x in R:
p=0
for y in R:
if'.'<I[y][x]:I[y][x]='.';I[p][x]='O';p+=1
if'.'>I[y][x]:p=y+1
c<1>d==S();*I,=zip(*I[::-1])
d=c-D.get(s:=str(I),-1e9)+1;c+=(1e9-c)//d*d+1;D[s]=c
S()
[Day 14] 335
*I,=open(c:=0)
R=range(100)
D={}
S=lambda:print(sum((len(I)-y)*I[y].count('O')for y in R))
while c<1e9:
for d in 0,1,2,3:
*I,=map(list,I)
for x in R:
p=0
for y in R:
if'.'<(C:=I[y][x]):I[y][x]='.';I[p][x]='O';p+=1
if'.'>C:p=y+1
c<1>d==S();*I,=zip(*I[::-1])
d=c-D.get(s:=str(I),-1e9)+1;c+=(1e9-c)//d*d+1;D[s]=c
S()
[Day 14] 332
*I,=open(c:=0)
R=range(100)
D={}
S=lambda:print(sum((100-y)*I[y].count('O')for y in R))
while c<1e9:
for d in 0,1,2,3:
*I,=map(list,I)
for x in R:
p=0
for y in R:
if'.'<(C:=I[y][x]):I[y][x]='.';I[p][x]='O';p+=1
if'.'>C:p=y+1
c<1>d==S();*I,=zip(*I[::-1])
d=c-D.get(s:=str(I),-1e9)+1;c+=(1e9-c)//d*d+1;D[s]=c
S()
[Day 14] 325
*I,=open(c:=0)
R=range(100)
D={}
S=lambda:print(sum((100-y)*I[y].count('O')for y in R))
while c<1e9:
for d in 0,1,2,3:
*I,=map(list,I)
for x in R:
p=0
for y in R:p=[p,y]['.'>(C:=I[y][x])];I[y][x]='#.'[y>p];I[p][x]=C;p+=C!='.'
c<1>d==S();*I,=zip(*I[::-1])
d=c-D.get(s:=str(I),-1e9)+1;c+=(1e9-c)//d*d+1;D[s]=c
S()
nice one
[Day 14] 323
*I,=open(c:=0)
R=range(100)
D={}
S=lambda:print(sum((100-y)*I[y].count('O')for y in R))
while c<1e9:
for d in R[:4]:
*I,=map(list,I)
for x in R:
p=0
for y in R:p=[p,y]['.'>(C:=I[y][x])];I[y][x]='#.'[y>p];I[p][x]=C;p+=C!='.'
c<1>d==S();*I,=zip(*I[::-1])
d=c-D.get(s:=str(I),-1e9)+1;c+=(1e9-c)//d*d+1;D[s]=c
S()```
Not working, but almost good:
[Day 14] (failing) 294
from itertools import*
*I,=open(c:=0)
R=range(100)
D={}
S=lambda:print(sum((100-y)*I[y].count('O')for y in R))
while c<1e9:
for d in R[:4]:
I=[[i for _,r in groupby(r,'.'.__gt__)for i in sorted(r)]for r in zip(*I[::-1])]
c<1>d==S()
d=c-D.get(s:=str(I),-1e9)+1;c+=(1e9-c)//d*d+1;D[s]=c
S()
Basically we need a version of S that can do it while the grid is sideways
Oh, nice save
doesn't save anything, but i guess 1e3 also works, don't need to loop the 1e9
I mean it doesn't matter because we just increase the loop counter
yea tru
are we allowing things that print a lot of other stuff but also the solution?
if so, c<1>d== can be removed lmao
No, it has to be exactly 2 outputs
[Day 14] 321
from itertools import*
*I,=open(c:=0)
R=range(100)
D={}
S=lambda:print(sum((x+1)*sum(I[y][x]>'.'for y in R)for x in R))
while c<1e9:
for d in R[:4]:
I=[[i for _,r in groupby(r,'.'.__gt__)for i in sorted(r)]for r in zip(*I[::-1])]
c<1>d==S()
d=c-D.get(s:=str(I),-1e9)+1;c+=(1e9-c)//d*d+1;D[s]=c
*I,=zip(*I[::-1]);S()
[Day 14] 319
from itertools import*
*I,=open(c:=0)
R=range(100)
D={}
S=lambda:print(sum((x+1)*(I[y][x]>'.')for y in R for x in R))
while c<1e9:
for d in R[:4]:
I=[[i for _,r in groupby(r,'.'.__gt__)for i in sorted(r)]for r in zip(*I[::-1])]
c<1>d==S()
d=c-D.get(s:=str(I),-1e9)+1;c+=(1e9-c)//d*d+1;D[s]=c
*I,=zip(*I[::-1]);S()
[Day 14] 316
from itertools import*
*I,=open(c:=0)
R=range(100)
D={}
S=lambda:print(sum((x+1)*(y[x]>'.')for y in I for x in R))
while c<1e9:
for d in R[:4]:
I=[[i for _,r in groupby(r,'.'.__gt__)for i in sorted(r)]for r in zip(*I[::-1])]
c<1>d==S()
d=c-D.get(s:=str(I),-1e9)+1;c+=(1e9-c)//d*d+1;D[s]=c
*I,=zip(*I[::-1]);S()
[Day 14] 239
l=*open(k:=0),
D={}
f=lambda l,t=0:print(sum(t:=t+r.count('O')for r in l))
while k<4e9:l=[eval("''.join(k)"+".replace('O.','.O')"*50)for k in zip(*l[::-1])];k<1!=f([*zip(*l)][::-1]);v=k-D.get(s:=str(l),-4e9)+1;k+=(4e9-k)//v*v+1;D[s]=k
f(l)```
biz from cg server π
went from 329 to 239 all of a sudden lmao
the eval replaces are genius
I mean this is technically brittle because it'll break if two consecutive parts of a cycle ever produce the same result (i.e. all rocks are being rolled into corners)
But I don't know if that's ever an issue that comes up
hehe bubbles
?
the rocks are bubbling up like in bubble sort
Ah
Yeah it's bubble sort lol
for once, bubble sort was the most efficient algorithm
who knew
Also I feel like that should be *99 in future golfs
Because it could theoretically hit a pathological case with no # in the middle of the row
most efficient in program length ig
we should use that sort that destroys the universe if it isn't already sorted
That's a never-to-any conversion right there if I've ever seen one
....wow.
[Day 14] 233 ```py
l=open(k:=0),
D={}
f=lambda l,t=0:print(sum(t:=t+r.count('O')for r in l))
while k<4e9:l=[eval("''.join(k)"+".replace('O.','.O')"*50)for k in zip(*l[::-1])],;k<1!=f([*zip(l)][::-1]);v=k-D.get(l,-4e9)+1;k+=(4e9-k)//vv+1;D[l]=k
f(l)
[Day 14] 237 but might have potential
l=*open(k:=0),
D={}
f=lambda l,t=0:print(sum(t:=t+r.count('O')for r in l))
while k<4e9:l=eval(eval("str((*zip(*l[::-1]),))"+".replace(\"O', '.\",\".', 'O\")"*99));k<1!=f([*zip(*l)][::-1]);v=k-D.get(l,-4e9)+1;k+=(4e9-k)//v*v+1;D[l]=k
f(l)
whut
LF line endings convert to nothing on a windows cmd terminal
double eval really is needed here
yeah
backticks used to work in python2 as it was an alias for repr(). but it was removed in py3
that would mean triple backticks are also allowed by extension
which would break markdown :p
`β`β`
nope?
those little things that make me have to double press an arrow to move through the backticks
Oh he cheated with zwsp lol
that would honestly be perfect for this golf
maybe
not really i don't know
yeah probably not
i just thought of it
Yeah the backtick repr and mixed indentation was what kept py2 in the running for a while
"str((*zip(*l[::-1]),))"+"..."
`str((*zip(*l[::-1]),))`+"..."
``` honestly what was i thinking
Remove the str call
Haha yea
here's one without it ```py
I mean you could always submit a python 2 golf
It's str(...) vs `...`
Why are the ticks doubled
single tick would have a string of a tuple so basically ```
(...).replace(...)....
Ahh gotcha
double would have ```py
"(...)".replace(...)....
Yeah I was like 'surely that can't be helpful' forgetting that we're doing bubble sort
anyways it removes the problem of double pressing
...for like most of the thing
but hey it's -2c
which i think is a golfing achievement
Btw you can use a triple string instead of backslashes for -0
yeah i already found the same too but didnt send update cuz same size
IMO it would be nicer to look at in triple form but I guess it doesn't really matter
true
still 234 though
wait a minute
i'm gonna try to python 2 golf
yeah i can't make it work
[Day 15 p1] 83
print(sum([n:=0,*[n:=(n+ord(c))*17%256for c in l]][-1]for l in input().split(",")))
[Day 15] (coincidentally) 256 ```py
A=B=n=0;b=eval('{},'256)
for y in input().split(','):
t=i=0
for x in y:x in'-='!=exec("I=i;T=t");t=(t+ord(x))17%256;i+=1
l=y[:I];g=y[I+1:];exec("b[T]"+[".pop(l,0)","[l]=int(g)"][g>'']);A+=t
for x in b:
n+=1;j=0
for z in x:j+=1;B+=njx[z]
print(A,B)
it's like the k<1!=exec() trick
ah right
[Day 15] 246 ```py
A=B=n=0;b=eval('{},'256)
for y in input().split(','):
t=i=0
for x in y:x in'-='!=exec("I=i;T=t");t=(t+ord(x))17%256;i+=1
b[T][l:=y[:I]]=int(g:=y[I+1:]or 0);g==0<b[T].pop(l,0);A+=t
for x in b:
n+=1;j=0
for z in x:j+=1;B+=njx[z]
print(A,B)
[Day 15] 237
b=eval('{},'*256)
p=q=u=0
for s in input().split(','):
d=s[:s.find('=')];k=0;*_,x,y,_=[k:=17*(k+ord(c))%256for c in s];p+=k
if s>d+'-':b[x][d]=s
else:b[y].pop(d,0)
for c in b:
u+=1;v=0
for i in c:v+=1;q+=u*v*int(c[i][-1])
print(p,q)
[Day 15] 236
b=eval('{},'*256)
p=q=u=0
for s in input().split(','):d=s[:s.find('=')];k=0;*_,x,y,_=[k:=17*(k+ord(c))%256for c in s];p+=k;s>d+'-'!=exec("b[x][d]=s")or b[y].pop(d,0)
for c in b:
u+=1;v=0
for i in c:v+=1;q+=u*v*int(c[i][-1])
print(p,q)
[Day 15] 232
b=eval('{},'*256)
p=q=u=0
for s in input().split(','):d=s[:s.find('=')];k=0;*_,x,y,_=[k:=17*(k+ord(c))%256for c in s];p+=k;s>d+'-'!=exec("b[x][d]="+s[-1])or b[y].pop(d,0)
for c in b:
u+=1;v=0
for i in c:v+=1;q+=u*v*c[i]
print(p,q)
[Day 15] 228 ```py
b=eval('{},'256)
p=q=u=0
for s in input().split(','):d=s[:s.find('=')];k=0;,x,y,=[k:=17*(k+ord(c))%256for c in s];p+=k;s>d+'-'!=exec("b[x][d]="+s)or b[y].pop(d,0)
for c in b:
u+=1;v=0
for i in c:v+=1;q+=uvc[i]
print(p,q)
[Day 15] alternate 228 ```py
b=eval('{},'256)
p=q=u=0
for s in input().split(','):d=s[:s.find('=')];k=0;x=s>d+'-';exec("b[[k:=17(k+ord(c))%256for c in s][~x-1]]"+[".pop(d,0)","[d]="+s][x]);p+=k
for c in b:
u+=1;v=0
for i in c:v+=1;q+=uvc[i]
print(p,q)
[Day 15] 220 ```py
b=eval('{},'256)
p=q=u=0
for s in input().split(','):d=s[:~(x:='='in s)];k=0;exec("b[[k:=17(k+ord(c))%256for c in s][~x-1]]"+[".pop(d,0)","[d]="+s][x]);p+=k
for c in b:
u+=1;v=0
for i in c:v+=1;q+=uvc[i]
print(p,q)
[Day 15] 219 ```py
b=eval('{},'256)
p=q=u=0
for s in input().split(','):x='='in s;d=s[:~x];k=0;exec("b[[k:=17(k+ord(c))%256for c in s][~-~x]]"+[".pop(d,0)","[d]="+s][x]);p+=k
for c in b:
u+=1;v=0
for i in c:v+=1;q+=uvc[i]
print(p,q)
i like the emoticons that python esoteric code can make
:~x
~-~
meh, just -x-2
but no fun :(
That isn't atomic
what
You can't multiply by it without adding brackets
yea, but you aren't multiplying it here lol
broken day 15 226 that i realized didn't work on real inputs a bit too late :c
i,g=input().split(','),globals()
p=q=0
for s in i:e='='in s;k=0;h=[k:=17*(k+ord(c))%256for c in s][~-~e];e>0!=exec(s+f'{h+1:03}')or g.pop(s[:~e],0);p+=k
for k in [*g][17:]:s=g[k]%1000;i+=s,;q+=g[k]//999*s*i.count(s)
print(p,q)
if something appears in two boxes it gets overwritten
but the globals idea could help
i was thinking of something like exec(f'b{h}'+s) but never got around to it
the b because identifiers can't start with a digit
though you could set it via a dictionary set and that would work fine
]Day 16] 426
I=*open(h:=0),
S=[]
for i in range(110):S+=[(0,i,1,0),(i,0,0,1),(i,109,0,-1),(109,i,-1,0)]
for p in S:
Q=[p];V=set()
while Q:
q=Q.pop(0);x,y,s,t=q
if(q in V)==0<=x<110>y>=0:V.add(q);Q+=[[(x+s,y+t,s,t)],[[(x+1,y,1,0),(x-1,y,-1,0)],[(x+s,y+t,s,t)]][s],[[(x,y+1,0,1),(x,y-1,0,-1)],[(x+s,y+t,s,t)]][t],[(x-t,y-s,-t,-s)],[(x+t,y+s,t,s)]][".-|/".find(I[y][x])]
V=len({(v[0],v[1])for v in V});h<1==print(V);h=max(h,V)
print(h)
guess its something to start at least
[Day 16] 405
I=*open(h:=0),
S=[]
for i in range(110):S+=[(0,i,1,0),(i,0,0,1),(i,109,0,-1),(109,i,-1,0)]
for p in S:
Q=[p];V=set()
while Q:
q=Q.pop(0);x,y,s,t=q
if(q in V)==0<=x<110>y>=0:V.add(q);Q+=[[z:=(x+s,y+t,s,t)],[[(x+1,y,1,0),(x-1,y,-1,0)],[z]][s],[[(x,y+1,0,1),(x,y-1,0,-1)],[z]][t],[(x-t,y-s,-t,-s)],[(x+t,y+s,t,s)]][".-|/".find(I[y][x])]
V=len({(v[0],v[1])for v in V});h<1==print(V);h=max(h,V)
print(h)
~~[Day 16] 404
I=*open(h:=0),
S=[]
for i in range(110):S+=[(0,i,1,0),(i,0,0,1),(i,109,0,-1),(109,i,-1,0)]
for p in S:
Q=[p];V=set()
while Q:
q=Q.pop(0);x,y,s,t=q
if(q in V)==0<=x<110>y>=0:V.add(q);Q+=[[z:=(x+s,y+t,s,t)],[[(x+1,y,1,0),(x-1,y,-1,0)],[z]][s],[[(x,y+1,0,1),(x,y-1,0,-1)],[z]][t],[(x-t,y-s,-t,-s)],[(x+t,y+s,t,s)]][".-|/".find(I[y][x])]
V=len({(v[0],v[1])for v in V});h<1>print(V);h=max(h,V)
print(h)
```~~
yeah main thing rn is that line w the if statement, gotta find a better way to decide directions
error
TypeError: '>' not supported between instances of 'int' and 'NoneType'
Oops
maybe we could fare better with complex coordinates?
[Day 16] 399
I=*open(h:=0),
for i in range(110):
for p in[(0,i,1,0),(i,0,0,1),(i,109,0,-1),(109,i,-1,0)]:
Q=[p];V=set()
while Q:
x,y,s,t=q=Q.pop(0)
if(q in V)==0<=x<110>y>=0:V.add(q);Q+=[[z:=(x+s,y+t,s,t)],[[(x+1,y,1,0),(x-1,y,-1,0)],[z]][s],[[(x,y+1,0,1),(x,y-1,0,-1)],[z]][t],[(x-t,y-s,-t,-s)],[(x+t,y+s,t,s)]][".-|/".find(I[y][x])]
V=len({(v[0],v[1])for v in V});h<1==print(V);h=max(h,V)
print(h)
perhaps, idk i have no idea how that works
[Day 16] 397
I=*open(h:=0),
for i in range(110):
for p in[(0,i,1,0),(i,0,0,1),(i,109,0,-1),(109,i,-1,0)]:
Q=[p];V=set()
while Q:x,y,s,t=q=Q.pop(0);Q+=[[],[z:=(x+s,y+t,s,t)],[[(x+1,y,1,0),(x-1,y,-1,0)],[z]][s],[[(x,y+1,0,1),(x,y-1,0,-1)],[z]][t],[(x-t,y-s,-t,-s)],[(x+t,y+s,t,s)]][(q in V)==0<=x<110>y>=0!=V.add(q)and" .-|/".find(I[y][x])]
V=len({(v[0],v[1])for v in V});h<1==print(V);h=max(h,V)
print(h)
[Day 16] 393
I=*open(h:=0),
for i in range(110):
for p in[(0,i,1,0),(i,0,0,1),(i,109,0,-1),(109,i,-1,0)]:
Q=[p];V=set()
while Q:x,y,s,t=q=Q.pop(0);Q+=[[],[z:=(x+s,y+t,s,t)],[[(x+1,y,1,0),(x-1,y,-1,0)],[z]][s],[[(x,y+1,0,1),(x,y-1,0,-1)],[z]][t],[(x-t,y-s,-t,-s)],[(x+t,y+s,t,s)]][(q in V)==0<=x<110>y>=0!=V.add(q)and" .-|/".find(I[y][x])]
V=len({(v[:2])for v in V});h<1==print(V);h=max(h,V)
print(h)
oh we can just
[Day 16] 392
I=*open(h:=0),
for i in range(110):
for p in[(0,i,1,0),(i,0,0,1),(i,109,0,-1),(109,i,-1,0)]:
Q=[p];V=set()
while Q:x,y,s,t=q=Q.pop();Q+=[[],[z:=(x+s,y+t,s,t)],[[(x+1,y,1,0),(x-1,y,-1,0)],[z]][s],[[(x,y+1,0,1),(x,y-1,0,-1)],[z]][t],[(x-t,y-s,-t,-s)],[(x+t,y+s,t,s)]][(q in V)==0<=x<110>y>=0!=V.add(q)and" .-|/".find(I[y][x])]
V=len({(v[:2])for v in V});h<1==print(V);h=max(h,V)
print(h)
lmao
I literally can't see what's changed
Q.pop(0) -> Q.pop()
Ah
wait a minute
im waiting
[Day 16] 391 ```py
I=*open(h:=0),
for i in range(110):
for p in[(0,i,1,0),(i,0,0,1),(i,109,0,-1),(109,i,-1,0)]:
Q=[p];V=set()
while Q:*Q,q=Q;x,y,s,t=q;Q+=[[],[z:=(x+s,y+t,s,t)],[[(x+1,y,1,0),(x-1,y,-1,0)],[z]][s],[[(x,y+1,0,1),(x,y-1,0,-1)],[z]][t],[(x-t,y-s,-t,-s)],[(x+t,y+s,t,s)]][(q in V)==0<=x<110>y>=0!=V.add(q)and" .-|/".find(I[y][x])]
V=len({(v[:2])for v in V});h<1==print(V);h=max(h,V)
print(h)
behold, the most convoluted 1b save in history
wait no nvm its the same length i forgot we already downgraded to 391
but this works
[Day 16] 387
I=*open(0),
h=i=0
exec('Q=[([0,r:=i//4,r,109][z:=i%4],[r,0,109,r][z],1+z//~1,~(~z%~2))];V=set()\nwhile Q:*Q,q=Q;x,y,s,t=q;Q+=[[],[z:=(x+s,y+t,s,t)],[[(x+1,y,1,0),(x-1,y,-1,0)],[z]][s],[[(x,y+1,0,1),(x,y-1,0,-1)],[z]][t],[(x-t,y-s,-t,-s)],[(x+t,y+s,t,s)]][(q in V)==0<=x<110>y>=0!=V.add(q)and" .-|/".find(I[y][x])]\nV=len({(v[:2])for v in V});h<1==print(V);h=max(h,V);i+=1;'*440)
print(h)
can probably improve Q=[([0,r:=i//4,r,109][z:=i%4],[r,0,109,r][z],1+z//~1,~(~z%~2))]
[Day 16] 376
I=*open(i:=0),
h=[]
exec('Q=[([0,r:=i//4,r,109][z:=i%4],[r,0,109,r][z],1+z//~1,~(~z%~2))];V=set()\nwhile Q:*Q,q=Q;x,y,s,t=q;Q+=[[],[z:=(x+s,y+t,s,t)],[[(x+1,y,1,0),(x-1,y,-1,0)],[z]][s],[[(x,y+1,0,1),(x,y-1,0,-1)],[z]][t],[(x-t,y-s,-t,-s)],[(x+t,y+s,t,s)]][(q in V)==0<=x<110>y>=0!=V.add(q)and" .-|/".find(I[y][x])]\nh+=len({(v[:2])for v in V}),;i+=1;'*440)
print(h[0],max(h))
~~[Day 16] 291
z=[]
s=open(0).read()
for i in range(l:=111):
for t in(i*l,1),(i,l):q=[t];v={s};V={s};exec('while q:\n c,d=t=q.pop();k=[-l,l,-1,1][d%9%4]\n if{t}-v and-~c*s[c:c+1]>" ":v|={t};V|={c};q+=[(c+d,d)for d in[{1,-1}-{-d},[d],[-k],{l,-l}-{-d},[k]][ord(s[c])%48%5]]');z+=len(V)-1,
print(z[0],max(z))```~~
~~[Day 16] 281
z=[]
s=open(0).read()
for i in range(l:=111):
for t in(i*l,1),(i,l):q=[t];v={s};V={s};exec('while q:\n c,d=t=q.pop();k=[-l,l,-1,1][d%9%4]\n if{t}-v and-~c*s[c:c+1]>" ":v|={t};V|={c};q+=[(c+d,d)for d in[{1,-1},[d],[-k],{l,-l},[k]][ord(s[c])%48%5]]');z+=len(V)-1,
print(z[0],max(z))```~~
[Day 16] 294
z=[]
s=open(0).read()
for i in range(l:=111):
for t in(i*l,1),(i,l),(i*l+l-2,-1):q=[t];v={s};V={s};exec('while q:\n c,d=t=q.pop();k=[-l,l,-1,1][d%9%4]\n if{t}-v and-~c*s[c:c+1]>" ":v|={t};V|={c};q+=[(c+d,d)for d in[{1,-1},[d],[-k],{l,-l},[k]][ord(s[c])%48%5]]');z+=len(V)-1,
print(z[0],max(z))```
[Day 16] 351
L=111
r="("*L+open(0).read()+"("*L
R=range
a=0,;b=1,;c=2,;d=3,;X=a+c;Y=b+d
T=[[]]*8+[*map(eval,"dcb"+"a"*6+"XcXYbYdabcdbadc")]
for B in[*R(1,l:=L*440,q:=444),*R(2,q,4),*R(l-q,l,4),*R(439,l,q)]:
n={B+q};h=n-n;E=n-n
while B:=n:n={E.add(x:=p//4)or[-L,1,L,-1][e]*4+e+x*4for p in B-h for e in T[ord(r[p//4])*4%40+p%4]};h|=B
a+=len(E),
print(a[1],max(a))```
not winning any prizes at plus 57 bytes, but here's my attempt
it does run a fair bit quicker
[Day 16] 272
*z,s=open(0).read(),
for i in range(l:=111):
for t in(i*l,1),(i,l),(i*l-2,-1):q=[t];v={s};z+=len({(c,v.add(t),k:=[l,-l,1,-1][d%9%4],q.extend((c+d,d)for d in[1,d,k,l,-k,-1,d,k,-l][ord(s[c])%48%5::5]))[0]for c,d in q if{t:=(c,d)}-v and-~c*s[c:c+1]>" "}),
print(z[0],max(z))```
i'm sorry, but our code runs a bit faster
really?
on my input+machine mine definitely runs 3 to 4 times faster
not really the aim of code golf ik but odd that it would be so different for you
is this usually supposed to take that long
Wdym? It takes maybe like 3-4s
is there like a reason why changing this makes it not stop (for me) ```py
if{t:=(c,d)}-v and-~cs[c:c+1]>" "
^^^^
if{t:=(c,d)}-v!=-~cs[c:c+1]>" "
[Day 18] 190 base ```py
p=q=1
x=y=0
f=lambda s:(abs(s)/2*s.imag,s.real)
for d,s,c in map(str.split,open(0)):b,a=f(1j**~-int(c[7])int(c[2:7],16));y+=a;q+=by;b,a=f(1j**"RDLU".index(d)int(s));x+=a;p+=bx
print(p,q)
[Day 18] 187 ```py
p=q=1
x=y=0
f=lambda s:(abs(s)/2*s.imag,s.real)
for X in open(0):d,s,c=X.split();b,a=f(1j**~-int(c[7])int(c[2:7],16));y+=a;q+=by;b,a=f(1j**"RDLU".index(d)int(s));x+=a;p+=bx
print(p,q)
[Day 18] 186 ```py
p=q=1
x=y=0
f=lambda s:(abs(s)/2*s.imag,s.real)
for X in open(0):d,s,c=X.split();b,a=f(1j**~-int(c[7])int(c[2:7],16));y+=a;q+=by;b,a=f(1j**"RDLU".find(d)int(s));x+=a;p+=bx
print(p,q)
nvm
whole thing doesn't work
[Day 18] 164 from cg server ```py
l,=open(0)
for p in 1,7:
y=a=3
for h in l:r,d,c=h.split();r=ord(r(2-p)or c[-2])%35%4;d=int(c[2:p]or d,p+9);f=7%~rd+d;y+=f;a+=d+(r-4&2-r)d(2y-f)
print(a//2)
[Day 18] 157
*l,=open(0)
for p in 1,7:
y=a=1
for h in l:r,d,c=h.split();r=ord(r*(2-p)or c[p])%35%4;d=int(c[2:p]or d,p+9);a+=d/2+(r-4&2-r)*d*y;y+=7%~r*d+d
print(int(a))```
[Day 19] part 1
R=-1
I={}
for l in open(0):
l=l.strip()
if''==l:R=0
elif R<0:n,r=l[:-1].split("{");I[n]=[x.split(':')for x in r.split(',')]
else:
p='in';exec(l[1:-1].replace(*',;'))
while p>'Z':
for r in I[p]:
if len(r)<2or eval(r[0]):p=r[-1];break
if'B'>p:R+=x+m+a+s
print(R)
do you mean 19
typo
[Day 19] part 1 253```py
I=open(0)
for l in I:
if"\n"==l:break
i=l.find("{")
exec(f"def {l[:i]}():\n"+"\n".join(f" if {j}();return"for j in (l[i+1:-2]+"():0#").split(",")))
t=[]
A=lambda:t.append(x+m+a+s)
R_=str
for l in I:exec(l[1:-2].replace(*",;"));in_()
print(sum(t))
[Day 19] part 1 249 ```py
I=open(0)
for l in I:
if"\n"==l:break
i=l.find("{");exec(f"def {l[:i]}():\n"+"\n".join(f" if {j}();return"for j in(l[i+1:-2]+"():R").split(",")))
A=lambda:t.append(x+m+a+s)
R_,t=str,
for l in I:exec(l[1:-2].replace(",;"));in_()
print(sum(t))
[Day 19] part 1 245
f,p=open(0).read().split('\n\n')
A=lambda:1+x+m+a+s
R=lambda:1
u=str.replace
for f in f.split():exec(u(u(u(u(u(f,':','and '),',','()or '),'{','=lambda:'),'}','()'),'in','IN'))
S=0
for i in p.split():exec(u(i,',',';')[1:-1]+';S+=IN()-1')
print(S)```
those u calls.,.
is this just part 1
[Day 19 Part 1] 239 ```py
f,p=open(0).read().split('\n\n')
A=lambda:1+x+m+a+s
R=lambda:1
u=str.replace
for f in f.split():exec(u(u(u(u(u(f,':','and '),',','()or '),'{','=lambda:'),'}','()'),'i_'))
S=0
for i in p.split():exec(u(i,',;')[1:-1]+';S+=_n()-1')
print(S)
yep lol
this is a code I found on reddit for part 2, seems like the most golfable code for now
ss = [ s.splitlines() for s in open(0).read().split( "\n\n" ) ]
r = {}
for l in ss[ 0 ]:
n, l = l.split( '{' )
r[ n ] = [ p.split( ":" ) for p in l[ : -1 ].split( ',' ) ]
def count( l, h ):
x = max( h[ 'x' ] - l[ 'x' ], 0 )
m = max( h[ 'm' ] - l[ 'm' ], 0 )
a = max( h[ 'a' ] - l[ 'a' ], 0 )
s = max( h[ 's' ] - l[ 's' ], 0 )
return x * m * a * s
t = 0
def process( l, h, w ):
if w == 'A':
global t
t += count( l, h )
return
if w == 'R':
return
for i in r[ w ]:
if len( i ) == 1:
process( l, h, i[ 0 ] )
if '<' in i[ 0 ]:
k, v = i[ 0 ].split( '<' )
nh = h.copy()
nh[ k ] = min( nh[ k ], int( v ) )
if count( l, nh ) > 0:
process( l.copy(), nh, i[ 1 ] )
l[ k ] = max( l[ k ], int( v ) )
if '>' in i[ 0 ]:
k, v = i[ 0 ].split( '>' )
nl = l.copy()
nl[ k ] = max( nl[ k ], int( v ) + 1 )
if count( nl, h ) > 0:
process( nl, h.copy(), i[ 1 ] )
h[ k ] = min( h[ k ], int( v ) + 1 )
process( { 'x': 1, 'm': 1, 'a': 1, 's': 1 },
{ 'x': 4001, 'm': 4001, 'a': 4001, 's': 4001 },
"in" )
print( t )```
[Day 19 Part 1] 227 ```py
f,p=open(0).read().split('\n\n')
A_=lambda:1+x+m+a+s
R_=lambda:1
for f in f.split():exec(f.translate({58:'and ',44:'()or ',123:'=lambda:',125:'()'}))
S=0
for i in p.split():exec(i.replace(*',;')[1:-1]+';S+=in()-1')
print(S)
is anything from this reusable for part 2 though?
eh no not really
ah
my code is pretty golfed but it needs regex
this ome does also already build a dict with info which would be useful for part 2 since else you still need to parse that either way? it can be golfed down quite a bit more either way, might be better than 2 completely separate things for both parts
[Day 19] 718 (π₯²)
A=-1
I={}
S=str.split
for l in open(0):
if' '>l:A=B=0
elif A<0:n,r=S(l[:-2],"{");I[n]=*map(S,S(r,','),':'*4),
else:
p='in';exec(l[1:~(l[-2]>"|")].replace(*',;'))
while'Z'<p:q=0;[p:=r[q:=-1]for r in I[p]if 1+q&(len(r)<2or eval(r[0]))];A+=p<'B'and x+m+a+s
Q=[('in',*[1,4000]*4)]
while Q:
p,xl,xh,ml,mh,al,ah,sl,sh=Q.pop(0)
if p<"B":B+=(xh-xl+1)*(mh-ml+1)*(ah-al+1)*(sh-sl+1)
if(xl<xh)*(ml<mh)*(al<ah)*(sl<sh)*(p in I):
for r in I[p]:
if len(r)<2:Q+=[(r[0],xl,xh,ml,mh,al,ah,sl,sh)]
else:[v,o,*n],r=r;n=int(''.join(n));Q+=[eval("(r,xl,xh,ml,mh,al,ah,sl,sh)".replace(*[v+'l',v+'h',f'max({v}l,{n+1})',f'min({v}h,{n-1})'][o=="<"::2]))];exec([f"{v}h=min({v}h,{n})",f"{v}l=max({v}l,{n})"][o=="<"])
print(A,B)
[Day 19] 659
B=-1
I={}
T=str.split;E=eval
for l in open(0):
if' '>l:B=C=0
elif B<0:n,r=T(l[:-2],"{");I[n]=*map(T,T(r,','),':'*4),
else:
p='in';exec(l[1:~(l[-2]>"|")].replace(*',;'))
while'Z'<p:q=0;[p:=r[q:=-1]for r in I[p]if-~q&(len(r)<2or E(r[0]))];B+=p<'B'and x+m+a+s
Q=[('in',*[1,4000]*4)]
for p,x,X,m,M,a,A,s,S in Q:
C+=~(X-x)*~(M-m)*~(A-a)*~(S-s)*(p<"B")
if(x<X)*(m<M)*(a<A)*(s<S)*(p in I):
for r in I[p]:Q+=(r[0],x,X,m,M,a,A,s,S)*(len(r)<2)or E("(r[1],x,X,m,M,a,A,s,S)".replace(*[L:=(v:=r[0][0]).lower(),U:=v.upper(),f'max({L},{(n:=E(r[0][2:]))+1})',f'min({U},{n-1})'][(o:=r[0][1]=="<")::2])),;exec([f"{U}=min({U},{n})",f"{L}=max({L},{n})"][o])
print(B,C)```
[Day 19] 559
B=C=S=0
I={}
T,E,F,*Q=str.split,eval,exec,('in',*[1,4000]*4)
for l in open(0):
if' '>l:S=1
elif S:
p='in';F(l[1:~(l[-2]>"|")].replace(*',;'))
while'Z'<p:q=0;[p:=r[q:=-1]for r in I[p]if-~q&(len(r)<2or E(r[0]))];B+=p<'B'and x+m+a+s
else:n,r=T(l[:-2],"{");I[n]=*map(T,T(r,','),':'*4),
for p,x,X,m,M,a,A,s,S in Q:C+=~(X-x)*~(M-m)*~(A-a)*~(S-s)*(p<"B");p in I!=F('for r in I[p]:Q+=E("r[-1],x,X,m,M,a,A,s,S".replace(*(len(r)<2)*"~~"or[L:=r[0][0],U:=L.upper(),f"{(n:=E(r[0][2:]))+1}",f"{n-1}"][(o:="<"in r[0])::2])),;F([f"{U}={n}",f"{L}={n}"][o])')
print(B,C)```
[Day 19] 536 ```py
B=C=S=0
I={}
T,E,F,Q=str.split,eval,exec,('in',[1,4000]4)
for l in open(0):S|=' '>l;' '<=l!=F(["n,r=T(l[:-2],'{');I[n]=map(T,T(r,','),':'4),","p='in';F(l[1:~(l[-2]>'|')].replace(',;'))\nwhile'Z'<p:q=0;[p:=r[q:=-1]for r in I[p]if-~q&(len(r)<2or E(r[0]))];B+=p<'B'and x+m+a+s"][S])
for p,x,X,m,M,a,A,s,S in Q:C+=~(X-x)~(M-m)~(A-a)~(S-s)(p<"B");p in I!=F('forr,R in I[p]:Q+=E("R,x,X,m,M,a,A,s,S".replace((len(r)<1)*"~~"or([L:=r[0][0],U:=L.upper()][o:="<"in r[0]],f"{(n:=E(r[0][2:]))-o-~-o}"))),;F([U,L][o]+f"={n}")')
print(B,C)
[Day 17] 277 from cg server ```py
from heapq import*
g=open(0).read()
for j in 4,11:
q,v=(0,0,1),(0,0,k:=142),{0}
while q:c,p,d=heappop(q);v>{t:=(p,d)}or[len(S:=g[p::D][1:i+1])==i!=heappush(q,(c+sum((ord(x)-48)%999for x in S),p+Di,D))for i in range(-~j//3,j)for D in[-k//d,k//d]];q*=p<20020;v|={t}
print(c)
did you just reply to a past version of yourself asking for a code yesterday? π
yep
[Day 19] 431
B=C=0
I={}
T,F,*Q=str.split,exec,('in',[1,4001]*4)
for l in open(0):' '<l!=F(["n,r=T(l[:-2],'{');I[n]=*map(T,T(r,','),':'*4),","p='in';F(l.strip()[1:-1].replace(*',;'))\nwhile'Z'<p:p=[R for*r,R in I[p]if[]==r or eval(r[0])][0];B+=p<'B'and x+m+a+s"]['{'<l])
for p,L in Q:
F(f"C+={'(%d-%d)*'*4%(*L,)}(p<'B')")
for*r,R in I.get(p,[]):Q+=(R,K:=L*1),;r>[]!=F(f'l=ord(z[0])//3%5*2^(">"in z);L[l]=K[l^1]={(z:=r[0])[2:]}+l%2')
print(B,C)
i dont even know where to start golfing for today
my input parsing alone is like 6 lines π
Yeah everything about today is horribly big
Is lcm worth the import from math or is there a shorter way to do it? Because we clearly need to use it today lol
pretty sure we just used math.lcm for day 8 as well
Yeah I just didn't remember lol
multiplying them all together gives the right answer for me too
but idk if thats universal
Yeah mine are numbers ~4000 that differ by like 100 in total
They might also be prime?
yup same
3917 3919 4007 4027 for me
prod worked for me
prod is still an import from math and is more characters
but a*b*c*d might be shorter depending on how we process it
I feel like the generic approach is actually probably shorter
maybe
at least its a better start off than yesterday
[Day 20] 538
import math
I={}
S=L=H=0
for i in open(0):
n,_,*d=i.replace(',','').split()
I[n[1:3]]=[n[0],n[0]=='&',d]
if'rx'in d:S=n[1:]
D={k:{j:0 for j in I if k in I[j][2]}for k in I}
C={k:0 for k in D[S]}
for P in range(9000):
L+=1;Q=[[d,0,'ro']for d in I['ro'][2]]
for e,p,o in Q:
if(e in C)>p:C[e]=P-C[e]
L+=1-p;H+=p;t,s,l=I.get(e,'***')
if(t=='%')>p:
s=1-s;I[e][1]=s
for d in l:Q.append([d,s,e])
if t=='&':
D[e][o]=p
for d in l:Q+=([d,1-all(D[e][d]for d in D[e]),e]),
if P==999:print(L*H)
print(math.lcm(*C.values()))
[Day 20] 510
import math
I={}
S=L=H=0
for i in open(0):
n,_,*d=i.replace(',','').split()
I[n[1:3]]=[n[0],n[0]=='&',d]
if'rx'in d:S=n[1:]
D={k:{j:0for j in I if k in I[j][2]}for k in I}
C={k:0for k in D[S]}
for P in range(9000):
L+=1;Q=[[d,0,'ro']for d in I['ro'][2]]
for e,p,o in Q:
if(e in C)>p:C[e]=P-C[e]
L+=1-p;H+=p;t,s,l=I.get(e,'***')
if(t=='%')>p:s=1-s;I[e][1]=s;Q+=[[d,s,e]for d in l]
if t=='&':D[e][o]=p;Q+=[[d,1-all(D[e][d]for d in D[e]),e]for d in l]
P==999==print(L*H)
print(math.lcm(*C.values()))
[Day 20] 471
I={}
R=1
S=L=H=P=0
for i in open(0):
n,_,*d=i.replace(*', ').split();I[n[1:3]]=[n[0],0,d]
if'rx'in d:S=n[1:]
D={k:{j:0for j in I if k in I[j][2]}for k in I}
C={k:0for k in D[S]}
while P<9000:
L+=1;Q=[[d,0,'ro']for d in I['ro'][2]]
for e,p,o in Q:
if(e in C)>p:R//=C[e]or 1;C[e]=P-C[e];R*=C[e]
L+=1-p;H+=p;t,s,l=I.get(e,'***')
if'&'==t:D[e][o]=p;s=all(D[e].values())
if(t<'&')>p or'&'==t:s=1-s;I[e][1]=s;Q+=[[d,s,e]for d in l]
P==999==print(L*H);P+=1
print(R)
[Day 20] 305 from cg server ```py
d={k[1:3]:[k[0],k.split()[2:],'rx'in k<(P:=k[1:3])]for k in open(0)}
l=h=i=0
t=1
while t<1e11:
q,z=('ro',0),i<1e3;i+=1
for n,v in q:
l+=z>v;h+=zv
if(k:=d.get(n))and'%'!=vk[0]:A,B,C=k;t=i**(P in BC);Z=k[2]=1-C(A<'&')-all(d[c][2]for c in d if n in"%s"%d[c]);q+=[(o[:2],Z)for o in B]
print(l*h,t)
I feel like you could somehow analyze the counter values and find some math solution for p1?
and p2 would also be trivial from there
[Day 20] functional part 2 ```py
d={k[1:3]:[k[0],k.split()[2:],'rx'in k<(P:=k[1:3])]for k in open(0)}
t=1
for node in d['ro'][1]:
s = 2048
for i in range(11):
n = d[node[:2]][1]
s += (len(n) - 1) * 2 ** i
node, = (i for i in n if d[i[:2]][0]=="%")
t *= s
print(t)
[Day 21] 330
D=1,1j,-1,-1j
s=65+65j
T=202300
e=enumerate
g={x+y*1j:c!='#'for y,L in e(open(0))for x,c in e(L.strip())}
C=[s+s*d for d in D]
r=lambda t=64:lambda S=s:len(eval("{p+d for p in"*t+'{S}'+"for d in D if g.get(p+d,0)}"*t))
print(r()(),T*(T*r(132)()+sum(map(r(),C)))+~-T*(~-T*r(131)()+sum(map(r(195),C)))+sum(r(130)(s+65*d)for d in D))```
[Day 21] 249
k=202300
n=enumerate
I={i+j*1jfor i,l in n(open(0))for j,c in n(l)if'$'<c}
e=lambda t,L="":len(eval("{d for p in"*t+"{65+65j}"+"for d in[p+1,p+1j,p-1,p-1j]if{d%s}&I}"%L*t))
print(e(64),~-k*(k*(e(132)+e(N:=131))-e(65))+k*e(196,".real%N+d.imag%N*1j"))```
[Day 21] 244
k,K=202300,393
I={i//132*K+i%132for i,c in enumerate(open(0).read())if'$'<c}
e=lambda t,L="":len(eval("{d for p in"*t+"{25610}"+"for d in[p+1,p+K,p-1,p-K]if{d%s}&I}"%L*t))
print(e(64),~-k*(k*e(132)+k*e(N:=131)-e(65))+k*e(196,"%N+(d+N)//K%N*K"))```
~~[Day 21] 193 from cg server ```py
S,=open(0,"rb").read()
i=A=B=0
n=202300
f=8645,
while f:
s=[]
for k in f:
if-1<k<len(S)>35<S[k]:S[k]=0;A+=(i<65)>i%2;B+=(n+i%2)(n+(i>65)^i%2);s+=[k+132,k-132,k+1,k-1]
f=s;i+=1
print(A,B)
[Day 21] 188 from cg server ```py
S,=open(0).read()
i=A=B=0
n=202300
f=8645,
while f:
s=[]
for k in f:
if-1<k<17291!='$'<S[k]:S[k]='';A+=(i<65)>i%2;B+=(n+i%2)(n+(i>65)^i%2);s+=k+132,k-132,k+1,k-1
f=s;i+=1
print(A,B)
[Day 21] 178 from cg server ```py
n=202300
S,e=open(0).read()+n'$'
i=A=B=0
f=8645,
while f:
f,s=f,;i+=1
for k in s:
if e<S[k]:S[k]=e;A+=i<i%266;B+=(n+~i%2)*(n+(i<67)^i%2);f+=k+132,k-132,k+1,k-1
print(A,B)