#AoC 2023 | Code Golfing

2369 messages Β· Page 3 of 3 (latest)

cerulean lantern
#

I need to figure out why ATO is throwing errors at me first

river kestrel
#

[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(q
all(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)

limpid stag
#

oop

cerulean lantern
#

I hate websockets

river kestrel
#

[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(q
all(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)

cerulean lantern
#

Someone submitted a 234 lol

river kestrel
#

oh

#

tf

#

quit this one

cerulean lantern
#

[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

river kestrel
#

IT EVEN HAS 3-LETTER NAMES

#

is this a practical joke

limpid stag
#

oh damn

cerulean lantern
#

[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))
river kestrel
#

[Day 11] 224 ```py
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 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

cerulean lantern
#

[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))
limpid stag
#

[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))
river kestrel
#

[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)))

cerulean lantern
#

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)))
river kestrel
#

surely there must be a way to make the r,s= and e= comprehensions work together in a non-zip() way

cerulean lantern
#

Β―_(ツ)_/Β―

cerulean lantern
#

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))
winter prawn
#

just allow .0 at this point 😩

#

1e6 works

winter prawn
cerulean lantern
#

...no? It's a 2 item comprehension that's later getting unpacked

winter prawn
cerulean lantern
#

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

winter prawn
#

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)```
eternal abyss
#

is that map(lambda ...) not longer than a genexpr

#

also assign enumerate to something

river kestrel
#

[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)

eternal abyss
#

[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

river kestrel
#

[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)

winter prawn
#

[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

river kestrel
#

[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)

winter prawn
#

[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)```
winter prawn
low hatch
#

who's doing the initial golf for today?

crimson turret
#

[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
winter prawn
# low hatch who's doing the initial golf for today?

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)))```
low hatch
#

damn

winter prawn
# low hatch 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

low hatch
#

yup

winter prawn
# low hatch 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

limpid stag
#

maybe just keeping a dict is smaller than using fuctools?

winter prawn
limpid stag
#

i tried but yeah it isnt πŸ™ƒ

winter prawn
#

How many bytes longer? πŸ€”

limpid stag
#

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

eternal abyss
#

you don't need the parens when indexing the dict

limpid stag
#

ah

#

still 30b so doesnt save over current solve

winter prawn
# limpid stag ah

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
cerulean lantern
# limpid stag i didnt actually write it out
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?)

limpid stag
#

[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])
cerulean lantern
#

Data should have synced by now, did you submit it?

limpid stag
#

yup

winter prawn
#

@cerulean lantern sending tc

limpid stag
cerulean lantern
#

@winter prawn does the 223 work or do I need to roll that back too

cerulean lantern
#

Actually I guess I could test that myself now I've added the answer

#

Presumably in the cg server

limpid stag
#

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

limpid stag
#

[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])
limpid stag
low hatch
#

[Day 13] 203```py
R=[0]99
for G in map(str.split,open(0).read().split('\n\n')):
for
g,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])

limpid stag
#

[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])
low hatch
#

[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))))

limpid stag
#

[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])
winter prawn
#

[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])```
river kestrel
#

[Day 13] 181 ```py
g,R=[0]99,
for
l,L in
open(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])

limpid stag
#

[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

cerulean lantern
#

Did you validate?

limpid stag
#

just submitted to bot

cerulean lantern
#

[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 πŸ™ƒ

limpid stag
#

oh yup

#

and another in the while loop

cerulean lantern
#

?

#

Actually yeah no that does work

limpid stag
#

ah right nvm

cerulean lantern
#

[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()
limpid stag
#

[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()
cerulean lantern
#

Wait, that works?

#

Wtf is that operator precedence

limpid stag
#

wdym?

cerulean lantern
#

Oh wait no we're multiplying the string lol

limpid stag
#

yeah

#

if the character is in the character * y then its the same character

cerulean lantern
#

Yeah

#

It's 6:30 give me a break πŸ™ƒ

limpid stag
#

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()
cerulean lantern
#

[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()
limpid stag
#

ah

#

yeah

cerulean lantern
#

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()
limpid stag
#

[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()
cerulean lantern
#

Damn we had the same idea but you did it better

limpid stag
#

:D

cerulean lantern
#

well I submitted first so they're both in the repo history ig

limpid stag
#

[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()
cerulean lantern
#

[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()
limpid stag
#

[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()
cerulean lantern
#

[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()
limpid stag
#

nice one

winter prawn
#

[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()```
cerulean lantern
#

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

winter prawn
cerulean lantern
#

I mean it doesn't matter because we just increase the loop counter

winter prawn
#

are we allowing things that print a lot of other stuff but also the solution?

#

if so, c<1>d== can be removed lmao

cerulean lantern
#

[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()
winter prawn
#

[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

cerulean lantern
#

Bruh

#

OH MY GOD

#

I love it

winter prawn
#

the eval replaces are genius

cerulean lantern
#

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

crimson turret
#

hehe bubbles

cerulean lantern
#

?

crimson turret
#

the rocks are bubbling up like in bubble sort

cerulean lantern
#

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

crimson turret
#

most efficient in program length ig
we should use that sort that destroys the universe if it isn't already sorted

cerulean lantern
#

That's a never-to-any conversion right there if I've ever seen one

river kestrel
#

[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)

limpid stag
#

[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)
river kestrel
#

nvm

#

mispaste

limpid stag
#

whut

river kestrel
#

LF line endings convert to nothing on a windows cmd terminal

limpid stag
#

ah

#

if only python allowed to use `` as quotes as well

river kestrel
#

double eval really is needed here

limpid stag
#

yeah

winter prawn
limpid stag
#

ah

#

:(

low hatch
#

which would break markdown :p

winter prawn
cerulean lantern
#
x = ```
uh oh we escaped markdown
``` + 'y'
#

@winter prawn

river kestrel
cerulean lantern
#

Oh he cheated with zwsp lol

river kestrel
#

maybe

#

not really i don't know

#

yeah probably not

#

i just thought of it

cerulean lantern
#

Yeah the backtick repr and mixed indentation was what kept py2 in the running for a while

river kestrel
cerulean lantern
#

Remove the str call

winter prawn
river kestrel
winter prawn
river kestrel
#

oh wait

#

this works too (i think) ```py
(*zip(*l[::-1]),)+"..."

#

yes it does

#

oh

cerulean lantern
#

Why are the ticks doubled

river kestrel
cerulean lantern
#

Ahh gotcha

river kestrel
#

double would have ```py
"(...)".replace(...)....

cerulean lantern
#

Yeah I was like 'surely that can't be helpful' forgetting that we're doing bubble sort

river kestrel
#

...for like most of the thing

#

but hey it's -2c

#

which i think is a golfing achievement

cerulean lantern
limpid stag
cerulean lantern
#

IMO it would be nicer to look at in triple form but I guess it doesn't really matter

limpid stag
#

true

river kestrel
#

wait a minute

#

i'm gonna try to python 2 golf

cerulean lantern
#

GL

#

I'm not even sure if py2 is on ato though

#

Nvm it is

river kestrel
#

yeah i can't make it work

limpid stag
#

[Day 15 p1] 83

print(sum([n:=0,*[n:=(n+ord(c))*17%256for c in l]][-1]for l in input().split(",")))
river kestrel
#

[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+=n
j
x[z]
print(A,B)

limpid stag
#

im so lost on what any of that does

#

x in'-='!=exec() ??

river kestrel
limpid stag
#

ah right

river kestrel
#

[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+=n
j
x[z]
print(A,B)

crimson turret
#

[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)
limpid stag
river kestrel
limpid stag
#

oh

#

smart one

low hatch
#

[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)

river kestrel
#

i like the emoticons that python esoteric code can make
:~x
~-~

river kestrel
cerulean lantern
river kestrel
#

what

cerulean lantern
#

You can't multiply by it without adding brackets

river kestrel
#

yea

#

that too

winter prawn
crimson turret
#

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

limpid stag
#

]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)
river kestrel
#

o.o

#

that's huge-

cerulean lantern
#

~~[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)
```~~
limpid stag
limpid stag
cerulean lantern
#

Oops

river kestrel
#

maybe we could fare better with complex coordinates?

limpid stag
#

[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)
limpid stag
#

[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)
cerulean lantern
#

[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)
limpid stag
#

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

cerulean lantern
#

I literally can't see what's changed

limpid stag
#

Q.pop(0) -> Q.pop()

cerulean lantern
#

Ah

river kestrel
#

wait a minute

limpid stag
#

im waiting

river kestrel
#

[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)

limpid stag
#

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))
winter prawn
#

~~[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))```~~
winter prawn
#

~~[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))```~~
winter prawn
#

[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))```
jolly cave
#

[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

winter prawn
#

[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))```
winter prawn
jolly cave
#

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

river kestrel
winter prawn
river kestrel
cerulean lantern
#

Short-circuiting?

#

Hm actually that's a stateless calculation

river kestrel
#

oh wait hold on

#

anyway where's the day 17 golf

river kestrel
#

[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

river kestrel
#

[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)

winter prawn
#

[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))```
limpid stag
#

[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)
limpid stag
#

typo

low hatch
#

[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))

winter prawn
river kestrel
#

those u calls.,.

river kestrel
#

[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)

winter prawn
winter prawn
# river kestrel [Day 19 Part 1] 239 ```py f,p=open(0).read().split('\n\n') A=lambda:1+x+m+a+s R=...

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 )```
river kestrel
#

[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)

limpid stag
river kestrel
limpid stag
#

ah

river kestrel
#

my code is pretty golfed but it needs regex

limpid stag
limpid stag
#

[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)
winter prawn
#

[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)```
winter prawn
#

[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)```
river kestrel
#

[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)

river kestrel
# river kestrel anyway where's the day 17 golf

[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+D
i,D))for i in range(-~j//3,j)for D in[-k//d,k//d]];q*=p<20020;v|={t}
print(c)

winter prawn
limpid stag
#

[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)
limpid stag
#

i dont even know where to start golfing for today

#

my input parsing alone is like 6 lines πŸ’€

cerulean lantern
#

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

limpid stag
#

pretty sure we just used math.lcm for day 8 as well

cerulean lantern
#

Yeah I just didn't remember lol

limpid stag
#

multiplying them all together gives the right answer for me too

#

but idk if thats universal

cerulean lantern
#

They might also be prime?

limpid stag
#

yup same

cerulean lantern
#

3917 3919 4007 4027 for me

limpid stag
#

4091, 3929, 4007, 3923

#

same third cycle nice

cerulean lantern
#

prod is still an import from math and is more characters

low hatch
#

but a*b*c*d might be shorter depending on how we process it

cerulean lantern
#

I feel like the generic approach is actually probably shorter

low hatch
#

maybe

limpid stag
# cerulean lantern Yeah everything about today is horribly big

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()))
limpid stag
#

[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)
river kestrel
#

[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+=z
v
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)

low hatch
#

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

low hatch
#

[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)

winter prawn
#

[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))```
winter prawn
#

[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"))```
winter prawn
#

[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"))```
river kestrel
#

~~[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)

river kestrel
#

[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)

river kestrel
#

[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%2
66;B+=(n+~i%2)*(n+(i<67)^i%2);f+=k+132,k-132,k+1,k-1
print(A,B)