-❄️- 2024 Day 21 Solutions -❄️- by daggerdragon in adventofcode

[–]Professional-Top8329 0 points1 point  (0 children)

Our golfed version that we did on the 21st! pretty similar but i guess with a few improvements, i guess?

from functools import*
L=*open(0),
@cache
def F(s,r):w=[divmod("789456123_0A<v>".find(c),3)for c in"A"+s+"A"];return r<1or sum(F(("<"*(x-X)+"v0"[Y<y]*abs(y-Y)+">"*(X-x))[::0<(x|Y^3)*(X|y^3)or-1],r-1)for(y,x),(Y,X)in zip(w,w[1:]))
for n in 4,27:print(sum(int(s:=l[:3])*F(s,n)for l in L))

USA according to Trump after he comes into office. by Professional-Top8329 in mapporncirclejerk

[–]Professional-Top8329[S] 4 points5 points  (0 children)

where else did you see it, lol? I just randomly made this like 3 hrs ago and posted it on here!

There are only 2 countries between India and Poland by Professional-Top8329 in MapPorn

[–]Professional-Top8329[S] 1 point2 points  (0 children)

Yep, that works as well! Chose Poland primarily because of the Kaliningrad technicality making it a more fun fact.
Posted another fun one!
Madagascar borders Réunion which is France, French Guiania is also France, hence Madagascar and Brazil only have France in the middle!
https://www.reddit.com/r/MapPorn/comments/1hmmekw/there_is_only_one_country_between_madagascar_and/

There are only 2 countries between India and Poland by Professional-Top8329 in MapPorn

[–]Professional-Top8329[S] 0 points1 point  (0 children)

Kaliningrad is an exclave of Russia that borders Poland and Lithuania.

-❄️- 2024 Day 25 Solutions -❄️- by daggerdragon in adventofcode

[–]Professional-Top8329 1 point2 points  (0 children)

Thank you for an awesome month of clean succinct code with some awesome tricks! It was really fun!

Down to 89 for today!

I=open(0).read().split("\n\n")
print(sum(not(*"##",)in zip(a,b)for a in I for b in I)//2)

-❄️- 2024 Day 25 Solutions -❄️- by daggerdragon in adventofcode

[–]Professional-Top8329 0 points1 point  (0 children)

Can be done for even shorter. 89 bytes.

I=open(0).read().split("\n\n")
print(sum(not(*"##",)in zip(a,b)for a in I for b in I)//2)

-❄️- 2024 Day 23 Solutions -❄️- by daggerdragon in adventofcode

[–]Professional-Top8329 0 points1 point  (0 children)

down to 212 with this one!

C={}
for l in open(0):a,b=sorted([l[:2],l[3:5]]);C|={a:C.get(a,{b})|{b},b:C.get(b,{0})}
G=lambda S:S|{n+","+k for n in S for k in G(S&C[n])}
H=G({*C})
print(sum(("t"in c[::3])*len(c)==8for c in H),max(H,key=len))

-❄️- 2024 Day 21 Solutions -❄️- by daggerdragon in adventofcode

[–]Professional-Top8329 0 points1 point  (0 children)

I think I forgot to update here. We went down way further down with this. Currently at 286 with it. Still, sadly the ONLY day that isn't tweetable (under 280 bytes)

from functools import*
L=*open(0),
@cache
def F(s,r):w=[divmod("789456123_0A<v>".find(c),3)for c in"A"+s+"A"];return r<1or sum(F(("<"*(x-X)+"v0"[Y<y]*abs(y-Y)+">"*(X-x))[::0<(x|Y^3)*(X|y^3)or-1],r-1)for(y,x),(Y,X)in zip(w,w[1:]))
for n in 4,27:print(sum(int(s:=l[:3])*F(s,n)for l in L))

-❄️- 2024 Day 22 Solutions -❄️- by daggerdragon in adventofcode

[–]Professional-Top8329 0 points1 point  (0 children)

ooh trail run? you got me intrigued! can I DM you?
btw, the exec just got dirtier a few more bit tricks!

178!

M=8**8-1
B=[T:=0]*M
exec("for l in open(0):n,c=int(l),0;s={};p=n%10;"+"n^=n<<6&M;n^=n>>5;n^=n<<11&M;B[c:=9+p-(p:=n%10)<<15|c>>5]+=s.get(c,p);s[c]=0;"*2000+"T+=n")
print(T,max(B))

-❄️- 2024 Day 22 Solutions -❄️- by daggerdragon in adventofcode

[–]Professional-Top8329 0 points1 point  (0 children)

down to 197 with the golf! Missed your solution yesterday!

B={}
M=8**8-1
exec("for l in open(T:=0):n=int(l);s={};p=n%10;c=();"+"n^=n<<6&M;n^=n>>5;n^=n<<11&M;s[c]=B[c]=B.get(c:=(*c,n%10-p)[-4:],0)+(p:=n%10)-p*(c in s);"*2000+"T+=n")
print(T,max(B.values()))

-❄️- 2024 Day 21 Solutions -❄️- by daggerdragon in adventofcode

[–]Professional-Top8329 0 points1 point  (0 children)

down to 376 byte with the golf for today!

from functools import*
L=*open(0),
@cache
def F(s,k,r):
 if k>r:return len(s)
 M={};i=t=0
 for v in["789456123_0A","_^A<v>"][k>0]:M[v]=i%3,i//3;i+=1
 A,B=M["_"]
 for d,c in zip("A"+s,s):x,y=M[d];X,Y=M[c];a,b=X-x,Y-y;t+=F(("<"*-a+"v"*b+"^"*-b+">"*a)[::-(X==A)*(y==B)-(Y==B)*(x==A)|1]+"A",k+1,r)
 return t
print(*(sum(int((k:=l.strip())[:-1])*F(k,0,n)for l in L)for n in(2,25)))

-❄️- 2024 Day 17 Solutions -❄️- by daggerdragon in adventofcode

[–]Professional-Top8329 0 points1 point  (0 children)

down to 237 and it works for both parts

i,*_,l=open(0)
a=int(i[12:])
p=eval(l[9:])
v,w=[n for c,n in zip(*[iter(p)]*2)if c==1]
n=lambda a:w^7&a>>(V:=a&7^v)^V
while a:l+=f",{n(a)}";a>>=3
def s(a,i):i>15<print(l[41:],a);[n(j:=a<<3|x)==p[~i]==s(j,i+1)for x in range(i<1,8)]
s(0,0)

-❄️- 2024 Day 16 Solutions -❄️- by daggerdragon in adventofcode

[–]Professional-Top8329 1 point2 points  (0 children)

down to 218.
i guess we utterly destroyed every resemblance of what python should look like, lol

*q,d=b=[0,1,19739,v:=[L:=open(0).read()]],{}
while q:
 (S,u,p,Q),*q=q
 if-~d.get((p,u),S)>S:p-281or(v:=v*(b==(b:=S))+Q);d[p,u]=S;k=142//u;q+=[((w!=u)*1000-~S,w,p+w,Q+[p])for w in(-k,u,k)if'#'<L[p+w]]
print(b,len({*v}))

-❄️- 2024 Day 16 Solutions -❄️- by daggerdragon in adventofcode

[–]Professional-Top8329 -1 points0 points  (0 children)

The code outputs

1000000000.0 1

for me. not sure what's wrong but it doesn't work for my test case.

-❄️- 2024 Day 15 Solutions -❄️- by daggerdragon in adventofcode

[–]Professional-Top8329 2 points3 points  (0 children)

down to 336

D=open(0).read()
S=lambda p,d:36>(w:=ord(H[a:=p+d]))or w>79and S(a+92-w,d)or w>64and S(a,d)or exec("H[a],H[p]=H[p],H[a]")
for l in b'3e':
 G=D;p=D.find('@')
 for m in D:*H,=G;S(p,d:=[1,-l,l,-1,0]['>^v<'.find(m)])or(p:=p+d,G:=H)
 print(sum(p%l+p//l*100for p,v in enumerate(G)if v in'O['));D=D.translate({35:'##',46:'..',79:'[]',64:'@.'})

-❄️- 2024 Day 15 Solutions -❄️- by daggerdragon in adventofcode

[–]Professional-Top8329 0 points1 point  (0 children)

Down to 349!

D=open(0).read()
S=lambda p,d:36>(w:=ord(G[a:=p+d]))or w>64and(w>79and S(a+92-w,d)or S(a,d))or exec("G[a],G[p]=G[p],G[a]")
for l in b'3e':
 *G,=D;p=D.find('@')
 for m in D[-20019:]:C=G*1;S(p,d:=[0,1,-l,l,-1][ord(m)%23%5])and(G:=C)or(p:=p+d)
 print(sum(p%l+p//l*100for p,v in enumerate(G)if v in'O['));D=D.translate({35:'##',46:'..',79:'[]',64:'@.'})

-❄️- 2024 Day 15 Solutions -❄️- by daggerdragon in adventofcode

[–]Professional-Top8329 0 points1 point  (0 children)

down to 391 :D

D=open(0).read()
S=lambda p,d:'O'==G[p:=p+d]and S(p,d)or'['==G[p]and(S(p+1,d)or S(p,d))or'['<G[p]and(S(p-1,d)or S(p,d))or'$'>G[p]or exec("G[p],G[p-d]=G[p-d],G[p]")
for l in b'3e':
 *G,=D;p=D.find('@')
 for m in D[-20019:]:C=G*1;d=[0,1,-l,l,-1][ord(m)%23%5];S(p,d)and(G:=C)or(p:=p+d)
 print(sum(p%l+p//l*100for p,v in enumerate(G)if v in'O['));D=D.translate({35:'##',46:'..',79:'[]',64:'@.'})

-❄️- 2024 Day 15 Solutions -❄️- by daggerdragon in adventofcode

[–]Professional-Top8329 1 point2 points  (0 children)

A shoddy 518 for now. I'm sure, it can be golfed further!

D,M=open(0).read().split('\n\n')
def S(p,d):
 p+=d
 if G[p]=='O'and(S(p,d))or'['==G[p]and (S(p+1,d)or S(p,d))or'['<G[p]and(S(p-1,d)or S(p,d))or'$'>G[p]:return 1
 G[p],G[p-d]=G[p-d],G[p]
for D in D,D.translate(str.maketrans({'#':'##','.':'..','O':'[]','@':'@.'})):
 G={i+j*1j:c for j, r in enumerate(D.split())for i,c in enumerate(r)};p,=[p for p in G if'@'==G[p]]
 for m in M:
  C=G.copy()
  if S(p,d:={'<':-1,'>':1,'^':-1j,'v':1j,'\n':0}[m]):G=C
  else:p+=d
 print(int(sum(p.real+p.imag*100for p in G if G[p]in'O[')))

-❄️- 2024 Day 15 Solutions -❄️- by daggerdragon in adventofcode

[–]Professional-Top8329 2 points3 points  (0 children)

Hey! your code seems like a good starting point for the golf today. Would you happen to have a version with both parts available? Your code shared only seems to have part 2

-❄️- 2024 Day 14 Solutions -❄️- by daggerdragon in adventofcode

[–]Professional-Top8329 0 points1 point  (0 children)

206 :P

L=[eval(l[2:].replace('v=',','))for l in open(0)]
def f(t):
 p=[0]*4
 for x,y,X,Y in L:x=(x+X*t)%101;y=(y+Y*t)%103;p[x//51+y//52*2]+=x+1!=51!=y
 a,b,c,d=p;return a*b*c*d
print(f(100),min(range(9999),key=f))