#AoC 2023 | Code Golfing

1 messages ยท Page 2 of 1

winter prawn
#

[Day 5] 385

s,*I=open(0)
S=s.split()
for P in 0,1:
 v=[[int(S[i]),(1,int(S[i+P]))[P]]for i in range(1,21,P+1)];n=[]
 for l in I:
  if"">l:v+=n;n=[]
  elif":">l[-2]:
   b,a,z=map(int,l.split());o=v;v=[]
   for f,l in o:A=a+z;F=f+l;N,V=[[[],[[f,l]]],[[[b,F-a]],[P:=[f,a-f]]],[[[f-a+b,A-f]],[Q:=[A,F-A]]],[[[f-a+b,l]],[]],[[[b,z]],[P,Q]]][4*(a>f<F>A)+2*(a<=f<A)+(a<F<=A)];n+=N;v+=V
 print(min(n)[0])```
jolly cave
#

the ratio of brackets to other characters is slowly increasing

winter prawn
jolly cave
#

amazing

cerulean lantern
#

[Day 5] 386 but if someone can figure out how to negate the condition it's a new best

s,*I=open(0)
S=s.split()
for P in 0,1:
 v=[[int(S[i]),(1,int(S[i+P]))[P]]for i in range(1,21,P+1)];n=[]
 for l in I:
  if"">l:v+=n;n=[]
  elif":">l[-2]:
   b,a,z=map(int,l.split());o=v;v=[]
   for f,l in o:F=f+l;N,V=[[[[b,z]],[P:=[f,a-f],Q:=[A:=a+z,F-A]]],[[[],[[f,l]]],[[[b,F-a]],[P]],[[[f-a+b,A-f]],[Q]],[[[f-a+b,l]],[]]][2*(a<=f<A)+(a<F<=A)]][~(a>f<F>A)];n+=N;v+=V
 print(min(n)[0])
#

(currently using ~ to invert the lookup but negating the condition without that would reduce the byte count)

jolly cave
#

couldn't you just swap round the elements it's indexing

cerulean lantern
jolly cave
#

oh right

cerulean lantern
#

Yeah I realised

cerulean lantern
#

GOT IT

#

[Day 5] 384

s,*I=open(0)
S=s.split()
for P in 0,1:
 v=[[int(S[i]),(1,int(S[i+P]))[P]]for i in range(1,21,P+1)];n=[]
 for l in I:
  if"">l:v+=n;n=[]
  elif":">l[-2]:
   b,a,z=map(int,l.split());o=v;v=[]
   for f,l in o:F=f+l;N,V=[[[[b,z]],[P:=[f,a-f],Q:=[A:=a+z,F-A]]],[[],[[f,l]]],[[[b,F-a]],[P]],[[[f-a+b,A-f]],[Q]],[[[f-a+b,l]],[]]][1-(a>f<F>A)+2*(a<=f<A)+(a<F<=A)];n+=N;v+=V
 print(min(n)[0])
#

(again, if someone can figure out a better way of not-ing that condition that would be great - currently it's 4c to not it)

winter prawn
limpid stag
#

[Day 5] 380

s,*I=open(0)
S=[*map(int,s.split()[1:])]
for P in 0,1:
 v=[*zip(S[::P+1],[x*P for x in S[P::P+1]])]
 for l in I:
  if"">l:v+=n;n=[]
  elif":">l[-2]:
   b,a,z=map(int,l.split());o=v;v=[]
   for f,l in o:F=f+l;N,V=[[[[b,z]],[P:=[f,a-f],Q:=[A:=a+z,F-A]]],[[],[[f,l]]],[[[b,F-a]],[P]],[[[f-a+b,A-f]],[Q]],[[[f-a+b,l]],[]]][1-(a>f<F>A)+2*(a<=f<A)+(a<F<=A)];n+=N;v+=V
 print(min(n)[0])
cerulean lantern
#

[Day 5] 384 Maybe easier to golf further?

s,*I=open(0)
S=s.split()
for P in 0,1:
 v=[[int(S[i]),(1,int(S[i+P]))[P]]for i in range(1,21,P+1)];n=[]
 for l in I:
  if"">l:v+=n;n=[]
  elif":">l[-2]:
   b,a,z=map(int,l.split());o=v;v=[]
   for f,l in o:N,V=[[[[b,z]],[P:=[f,a-f],Q:=[A:=a+z,F:=f+l-A]]],[[],[[f,l]]],[[[b,F+z]],[P]],[[[f-a+b,A-f]],[Q]],[[[f-a+b,l]],[]]][1-(a>f>0<F)+2*(a<=f<A)+(-z<F<=0)];n+=N;v+=V
 print(min(n)[0])
winter prawn
#

yea

limpid stag
#

oops i still had code above it that made it not die

cerulean lantern
#

It's another 384 if you define n oops no it's 385

winter prawn
#

\n as well

cerulean lantern
#

Yeah

#

*semi

#

It has to be defined on the same line as v

winter prawn
cerulean lantern
#

Yeah

#

[Day 5] 384 (fixed it)

s,*I=open(0)
*S,=map(int,s.split()[1:])
for P in 0,1:
 v=[*zip(S[::P+1],[x*P for x in S[P::P+1]])];n=[]
 for l in I:
  if"">l:v+=n;n=[]
  elif":">l[-2]:
   b,a,z=map(int,l.split());o=v;v=[]
   for f,l in o:F=f+l;N,V=[[[[b,z]],[P:=[f,a-f],Q:=[A:=a+z,F-A]]],[[],[[f,l]]],[[[b,F-a]],[P]],[[[f-a+b,A-f]],[Q]],[[[f-a+b,l]],[]]][1-(a>f<F>A)+2*(a<=f<A)+(a<F<=A)];n+=N;v+=V
 print(min(n)[0])
limpid stag
#

hold up

#

none of these even give the right answer for me

winter prawn
#

lmaooo

#

wot

limpid stag
#

like also not without mychanges

cerulean lantern
#

...send me your input file (and answers) -- (in DMs not publicly)

cerulean lantern
#

time to test the extra data folder

low hatch
cerulean lantern
#

Does that save any?

low hatch
#

-1

#
(1,int(S[i+P]))[P]
1+P*-~int(S[i+P])
cerulean lantern
#

Cool

#

but first we need to figure out why we're getting WA

low hatch
#

yeah I was gonna post the 383 but that happened

limpid stag
cerulean lantern
#

Oh lol nw

#

Ok the extra-data does work

limpid stag
#

this is the last one that gives correct answer

cerulean lantern
#

(good to know)

#

Ok I guess I'll go revert to 389 lmao

winter prawn
cerulean lantern
#

'this is the last one that gives correct answer'

#

So I'm gonna go with yes

winter prawn
# cerulean lantern 'this is the last one that gives correct answer'

umm, try this
[Day 5] 386 i think it'll work

s,*I=open(0)
*S,=map(int,s.split()[1:])
for P in 0,1:
 v=[*zip(S[::P+1],[x*P for x in S[P::P+1]])];n=[]
 for l in I:
  if"">l:v+=n;n=[]
  elif":">l[-2]:
   b,a,z=map(int,l.split());o=v;v=[]
   for f,l in o:F=f+l;N,V=[[[[b,z]],[P:=[f,a-f],Q:=[A:=a+z,F-A]]],[[],[[f,l]]],[[[b,F-a]],[P]],[[[f-a+b,A-f]],[Q]],[[[f-a+b,l]],[]]][1-(a>f<F>A)+2*(a<=f<A)+(a<F<=A)];n+=N;v+=V
 print(min(v+n)[0])```
#

i think the min was is v for him

limpid stag
#

yup thats it

#

does the v=zip actually save any bytes over the loop it was before yet?

#

if not, it does now

[Day 5] 385

s,*I=open(0)
*S,=map(int,s.split()[1:])
for P in 0,1:
 *v,=zip(S[::P+1],[x*P for x in S[P::P+1]]);n=[]
 for l in I:
  if"">l:v+=n;n=[]
  elif":">l[-2]:
   b,a,z=map(int,l.split());o=v;v=[]
   for f,l in o:F=f+l;N,V=[[[[b,z]],[P:=[f,a-f],Q:=[A:=a+z,F-A]]],[[],[[f,l]]],[[[b,F-a]],[P]],[[[f-a+b,A-f]],[Q]],[[[f-a+b,l]],[]]][1-(a>f<F>A)+2*(a<=f<A)+(a<F<=A)];n+=N;v+=V
 print(min(v+n)[0])
cerulean lantern
#

[Day 5] 385 (this is what's committed - we should try merging the other 385 into it nvm they're just two sections with equivalent alternatives)

s,*I=open(0)
S=s.split()
for P in 0,1:
 v=[[int(S[i]),1+P*-~int(S[i+P])]for i in range(1,21,P+1)];n=[]
 for l in I:
  if"">l:v+=n;n=[]
  elif":">l[-2]:
   b,a,z=map(int,l.split());o=v;v=[]
   for f,l in o:N,V=[[[[b,z]],[P:=[f,a-f],Q:=[A:=a+z,F:=f+l-A]]],[[],[[f,l]]],[[[b,F+z]],[P]],[[[f-a+b,A-f]],[Q]],[[[f-a+b,l]],[]]][1-(a>f>0<F)+2*(a<=f<A)+(-z<F<=0)];n+=N;v+=V
 print(min(v+n)[0])
winter prawn
cerulean lantern
low hatch
#

[Day 5] 384 ```py
s,*I=open(0)
S,=map(int,s.split()[1:])
for P in 0,1:
v,=zip(S[::P+1],[xP for x in S[P::P+1]]);n=[]
for l in I:
if" ">l:v+=n;n=[]
if"/"<l[-6:]:
b,a,z=map(int,l.split());o=v;v=[]
for f,l in o:F=f+l;N,V=[[[[b,z]],[P:=[f,a-f],Q:=[A:=a+z,F-A]]],[[],[[f,l]]],[[[b,F-a]],[P]],[[[f-a+b,A-f]],[Q]],[[[f-a+b,l]],[]]][1-(a>f<F>A)+2
(a<=f<A)+(a<F<=A)];n+=N;v+=V
print(min(v+n)[0])

cerulean lantern
#

Before that:

#

[Day 5] 384

s,*I=open(0)
S=s.split()
for P in 0,1:
 v=[[int(S[i]),1+P*-~int(S[i+P])]for i in range(1,21,P+1)];n=[]
 for l in I:
  if"">l:v+=n;n=[]
  elif":">l[-2]:
   b,a,z=map(int,l.split());o=v;v=[]
   for f,l in o:N,V=[[[[b,z]],[P:=[f,a-f],Q:=[A:=a+z,F:=f+l-A]]],[[],[[f,l]]],[[[b,F+z]],[P]],[[[f-a+b,A-f]],[Q]],[[[f-a+b,l]],[]]][1-(a>f>0<F)+2*(a<=f<A)+(-z<F<1)];n+=N;v+=V
 print(min(v+n)[0])
#

Equivalent for all inputs

#

Right now what was your change?

#

Oh the -6

#

Hm

low hatch
#

yeah

cerulean lantern
#

Remind me how this works again

low hatch
#

it breaks if there's a 4 digit length anywhere

#
"\n"[-6:] == "\n"
"...-to-... map:\n"[-6:] == " map:\n"
"... 32048327\n"[-6:] == "48327\n"
#

and "\n" < " " < "/" < "0"

eternal abyss
#

a 4 digit length?

cerulean lantern
#

\d+ \d+ \d{4}$

#

There isn't in my input, I'll check ducky's

#

None there either

#

I think it's valid

#

Do you wanna apply that to the other 384 then?

low hatch
#

alr

#

[Day 5] 383 ```py
s,I=open(0)
S=s.split()
for P in 0,1:
v=[[int(S[i]),1+P
-~int(S[i+P])]for i in range(1,21,P+1)];n=[]
for l in I:
if" ">l:v+=n;n=[]
if"/"<l[-6:]:
b,a,z=map(int,l.split());o=v;v=[]
for f,l in o:N,V=[[[[b,z]],[P:=[f,a-f],Q:=[A:=a+z,F:=f+l-A]]],[[],[[f,l]]],[[[b,F+z]],[P]],[[[f-a+b,A-f]],[Q]],[[[f-a+b,l]],[]]][1-(a>f>0<F)+2*(a<=f<A)+(-z<F<1)];n+=N;v+=V
print(min(v+n)[0])

cerulean lantern
#

I meant in terms of submitting it to the bot lmao

ionic jetty
low hatch
#

both my accounts have the same input lol

cerulean lantern
#

Lmao nice

#

Do you wanna go submit your improvement btw or shall I go submit it

low hatch
#

do I submit in the code.golf server?

cerulean lantern
#

Yeah

#

Because we don't have the bot here

low hatch
#

done

cerulean lantern
#

๐Ÿ‘

#

pfft, someone made their own server for the bot

limpid stag
#
*v,=zip(S[::P+1],map(P.__mul__,S[P::P+1]));n=[]
*v,=zip(S[::P+1],[x*P for x in S[P::P+1]]);n=[]`

same length but thought it was neat

cerulean lantern
#

This is where coconut would be really cool
(*)$P

river kestrel
#

hii-

#

oh

#

o.o

limpid stag
#

[Day 5] 376

S,*I=[[int(x)for x in l.split()if"/"<x<":"]for l in open(0)]
for P in 0,1:
 *v,=zip(S[::P+1],map(P.__mul__,S[P::P+1]));n=[]
 for l in I:
  if l:
   b,a,z=l;o=v;v=[]
   for f,l in o:N,V=[[[[b,z]],[P:=[f,a-f],Q:=[A:=a+z,F:=f+l-A]]],[[],[[f,l]]],[[[b,F+z]],[P]],[[[f-a+b,A-f]],[Q]],[[[f-a+b,l]],[]]][1-(a>f>0<F)+2*(a<=f<A)+(-z<F<1)];n+=N;v+=V
  else:v+=n;n=[]
 print(min(v+n)[0])
cerulean lantern
#

[Day 5] 375

S,*I=[[int(x)for x in l.split()if"/"<x<":"]for l in open(0)]
for P in 0,1:
 *v,=zip(S[::P+1],map(P.__mul__,S[P::P+1]));n=[]
 for l in I:
  if l:
   b,a,z,o,*v=*l,v
   for f,l in o:N,V=[[[[b,z]],[P:=[f,a-f],Q:=[A:=a+z,F:=f+l-A]]],[[],[[f,l]]],[[[b,F+z]],[P]],[[[f-a+b,A-f]],[Q]],[[[f-a+b,l]],[]]][1-(a>f>0<F)+2*(a<=f<A)+(-z<F<1)];n+=N;v+=V
  else:v+=n;n=[]
 print(min(v+n)[0])
river kestrel
#

[day 5] 374 ```py
S,*I=[[int(x)for x in l.split()if"/"<x<":"]for l in open(0)]
for P in 0,1:
*v,=zip(S[::P+1],map(P.mul,S[P::P+1]));n=[]
for l in I:
if l:
b,a,z,o,*v=l,v
for f,l in o:N,V=[[[[b,z]],[P:=[f,a-f],Q:=[A:=a+z,F:=f+l-A]]],[[],[[f,l]]],[[[b,F+z]],[P]],[[[g:=f-a+b,A-f]],[Q]],[[[g,l]],[]]][1-(a>f>0<F)+2
(a<=f<A)+(-z<F<1)];n+=N;v+=V
else:v+=n;n=[]
print(min(v+n)[0])

winter prawn
#

also, damn, __mul__

limpid stag
winter prawn
#

[Day 5] 370

S,*I=[[int(x)for x in l.split()if":">x]for l in open(0)]
for P in 0,1:
 *v,=zip(S[::P+1],map(P.__mul__,S[P::P+1]));n=[]
 for l in I:
  if l:
   b,a,z,o,*v=*l,v
   for f,l in o:N,V=[[[[b,z]],[P:=[f,a-f],Q:=[A:=a+z,F:=f+l-A]]],[[],[[f,l]]],[[[b,F+z]],[P]],[[[g:=f-a+b,A-f]],[Q]],[[[g,l]],[]]][1-(a>f>0<F)+2*(a<=f<A)+(-z<F<1)];n+=N;v+=V
  else:v+=n;n=[]
 print(min(v+n)[0])```
limpid stag
#

..oh

winter prawn
#

what would the theoretically shortest solution be though anyone tried that?

#

where p1's solution is just fed into p2 with ranges

#

it will surely work given enough memory

low hatch
#

generating a dict mapping for each number might be shorter too

winter prawn
#

also, use this, cz the solution is b,a,s,e,*d
[Day 5] 370

S,*I=[[int(x)for x in l.split()if":">x]for l in open(0)]
for P in 0,1:
 *d,=zip(S[::P+1],map(P.__mul__,S[P::P+1]));n=[]
 for l in I:
  if l:
   b,a,s,e,*d=*l,d
   for f,l in e:N,D=[[[[b,s]],[P:=[f,a-f],Q:=[A:=a+s,F:=f+l-A]]],[[],[[f,l]]],[[[b,F+s]],[P]],[[[g:=f-a+b,A-f]],[Q]],[[[g,l]],[]]][1-(a>f>0<F)+2*(a<=f<A)+(-s<F<1)];n+=N;d+=D
  else:d+=n;n=[]
 print(min(d+n)[0])```
eternal abyss
#

I think we should have a rule where if you want to make a change to variable names, you should make a character reduction first

cerulean lantern
#

Seems reasonable

winter prawn
cerulean lantern
#

yeah but you changed the names after that so you need another save

#

I'm sure that the condition index can be shortened somehow, it's just a matter of how

#

Might involve tables

#

(i.e. to simplify the expression, not in the code)

#

I see a save ๐Ÿ‘€

#

I'm on the bus to uni though so you have like 20 minutes to snipe it @winter prawn

winter prawn
eternal abyss
#

i would have a look but i'm still doing the day

cerulean lantern
#

Wait actually my save might not even work

#

We'll see

#

actually yeah nvm lol

limpid stag
#

[Day 5] 367

S,*I=[[int(x)for x in l.split()if":">x]for l in open(0)]
for P in 0,1:
 *d,=zip(S[::P+1],map(P.__mul__,S[P::P+1]));n=[]
 for l in I:
  if l:
   b,a,s,e,*d=*l,d
   for f,l in e:N,D=[[[b,s]],[],[[b,(F:=f+l-(A:=a+s))+s]],[[g:=f-a+b,A-f]],[[g,l]],[P:=[f,a-f],Q:=[A,F]],[[f,l]],[P],[Q],[]][1-(a>f>0<F)+2*(a<=f<A)+(-s<F<1)::5];n+=N;d+=D
  else:d+=n;n=[]
 print(min(d+n)[0])
cerulean lantern
#

damn I was trying to get it to say PLANT

limpid stag
#

lmao

cerulean lantern
#

Wait, how does this work?

eternal abyss
#

just save more characters to make it happen

#

at least until we make a variable name have utility in the program

limpid stag
cerulean lantern
#

Oooh

#

Nicely done

limpid stag
#

:D

#

i didnt dare to actually touch the logic

#

i have no idea what it does

#

just rearranged some thigns

cerulean lantern
#

This probably means that another reordering of the logic is in order

#

or in other words the thing I've been doing for the past 20 minutes is mostly thrown out

#

Actually that isn't really true I can reuse most of it

limpid stag
cerulean lantern
#

(yeah but I was working on list indexing)

limpid stag
#

ah

cerulean lantern
#

((but actually it's probably fine because the tables I've made are still somewhat useful))

limpid stag
#

the expression 1-(a>f>0<F)+2*(a<=f<A)+(-s<F<1) can probably be improved

#

but idk if anyone remembers why or what it does

cerulean lantern
#

That's literally what I'm working on

#

I'm trying to make kmaps that sum to the right index

limpid stag
#

ahhh

cerulean lantern
#

But given your save it's worth trying to reorder the stuff in the middle first

limpid stag
#

hmmm

cerulean lantern
#

[Day 5] 366

S,*I=[[int(x)for x in l.split()if":">x]for l in open(0)]
for p in 0,1:
 *T,=zip(S[::p+1],map(p.__mul__,S[p::p+1]));n=[]
 for h in I:
  if h:
   P,L,A,N,*T=*h,T
   for o,h in N:O,D=[[[P,(F:=o+h-(a:=L+A))+A]],[],[[g:=o-L+P,a-o]],[[P,A]],[[g,h]],[p:=[o,L-o]],[[o,h]],[Q:=[a,F]],[p,Q],[]][((L>o)+3*(F>0)-(o>a)-(F>-A))%5::5];n+=O;T+=D
  else:T+=n;n=[]
 print(min(T+n)[0])
#

PLANT!
oh NO

limpid stag
#

wow

#

i cant even see where you saved a byte

cerulean lantern
#

Reordered the stuff in the list in order to save a byte in the index

limpid stag
#

oh i see

#

damn nice

cerulean lantern
#

Was hoping for more but unfortunately I could only get it to work with -1 being the last unique index

#

Wait

#

I'm dumb

limpid stag
#

my brain gave up on comprehending the code now that all letters got swapped around lmao

winter prawn
cerulean lantern
#

[Day 5] 364

S,*I=[[int(x)for x in l.split()if":">x]for l in open(0)]
for p in 0,1:
 *T,=zip(S[::p+1],map(p.__mul__,S[p::p+1]));n=[]
 for h in I:
  if h:
   P,L,A,N,*T=*h,T
   for o,h in N:O,D=[[[g:=o-L+P,h]],[[P,(F:=o+h-(a:=L+A))+A]],[],[[g,a-o]],[[P,A]],[],[p:=[o,L-o]],[[o,h]],[Q:=[a,F]],[p,Q]][(L>o)+3*(F>0)-(o>a)-(F>-A)+1::5];n+=O;T+=D
  else:T+=n;n=[]
 print(min(T+n)[0])
#

Easy save I was just stupid the first time

limpid stag
#

[Day 5] 369 but might have some potential for more saves?

S,*I=[[int(x)for x in l.split()if":">x]for l in open(0)]
for p in 0,1:
 *K,=zip(S[::p+1],map(p.__mul__,S[p::p+1]));n=[]
 for _ in I:
  if _:D,U,C=_;K=sum([[n:=n+(O:=[[[g:=o-U+D,h]],[[D,(F:=o+h-(a:=U+C))+C]],[],[[g,a-o]],[[D,C]],[],[p:=[o,U-o]],[[o,h]],[Q:=[a,F]],[p,Q]][(U>o)+3*(F>0)-(o>a)-(F>-C)+1::5])[0],O[1]][1]for o,h in K],[])
  else:K+=n;n=[]
 print(min(K+n)[0])
#

lots of whitespace and a var removed

eternal abyss
#

don't think quadratic formula ideas are worth it today

cerulean lantern
#

Yeah I think lening a listcomp is the best way to do it

eternal abyss
#

that OBOE is just too annoying

limpid stag
#

what's time limit?

low hatch
#

I got this for input processing: ```py
I,=open(0)
for r in"; ":
for t,d in zip(
[map(int,l[9:].replace(r,"").split())for l in I]):
print(t,d)

cerulean lantern
eternal abyss
#

BTW we don't need to iterate up to the digit

eternal abyss
#

tho it's probably optimal characterwise for p2

cerulean lantern
#

My brute-force solution only takes 3s so we're probably not in any danger of hitting the kill

ionic jetty
#

haven't completely given up on quadratic formula yet. because in this specific case, because we want the closest integer, it can be computed by looking at the remainder of the discriminant mod 4 (I think)

cerulean lantern
limpid stag
low hatch
#

yes

cerulean lantern
#

It's ceil for the small root and floor for the big root

eternal abyss
#

we get a +1 anyways

#

so assuming we never actually hit distance we can just do two floors

cerulean lantern
ionic jetty
limpid stag
#

[Day 6] 166

t,d=[x.split()[1:]for x in open(0)]
for r in zip(t,d),[[''.join(t),''.join(d)]]:print(eval('*'.join([str(sum(i*(int(s)-i)>int(m)for i in range(int(s))))for s,m in r])))
low hatch
#

[Day 6] 145 initial ```py
I,=open(0)
for r in"; ":
a=1
for t,d in zip(
[map(int,l[9:].replace(r,"").split())for l in I]):
a*=sum(d<i*(t-i)for i in range(t))
print(a)

limpid stag
#

ah ok

cerulean lantern
low hatch
#

pretty much, yeah

cerulean lantern
#

I'm making fun of you for writing unreadable code /j

#

[Day 6] 142 trivially

*I,=open(0)
for r in"; ":
 a=1
 for t,d in zip(*[map(int,l[9:].replace(r,"").split())for l in I]):a*=sum(d<i*(t-i)for i in range(t))
 print(a)
limpid stag
#

fuck

low hatch
#

oh facepalm

low hatch
eternal abyss
#
sum(d<i*(t-i)for i in range(t))
(t*t-4*d)**.5+
jolly cave
#

ik it's a worse byte count but i don't like doing brute forces even for golf
[Day 6] 174py def b(t,d):t=int(t);A=(t*t/4-int(d))**.5;return int(A+t/2)-int(t/2-A) x=1;T=D="";r=open(0).read().split() for i in 1,2,3,4:x*=b(r[i],r[i+5]);T+=r[i];D+=r[i+5] print(x,b(T,D))

eternal abyss
#

k you get 17 characters to figure out the OBOE

#

that's more than I thought

#

maybe there is merit

#

I guess the + is premature since we might have some like bitwise thing

cerulean lantern
#

[Day 6] 141

*I,=open(0)
for r in"; ":a=1;[a:=a*sum(d<i*(t-i)for i in range(t))for t,d in zip(*[map(int,l[9:].replace(r,"").split())for l in I])];print(a)
winter prawn
cerulean lantern
tribal wadi
#

Day6 part1 155

a=open(0).split()
s=0
for t,d in zip(a[1:],a[6:]):
 t=int(t)
 d=int(d)
 if t%2:s+=int((1+(4*(t//2*(t+1)//2-d)+1)**.5))
 else:s+=1+2*int(((t/2)**2-d)**.5)
print(s)```
jolly cave
#

sounds good

cerulean lantern
#

(and a language variant isn't really doable because how do I regex against bf lmao)

eternal abyss
#

oh that's smart actually

cerulean lantern
#

Lmao rip

eternal abyss
#

forgot the other discriminant form exists

winter prawn
jolly cave
cerulean lantern
#

That wouldn't work because a) the day parameter is an int (commands being nice and parsing it for me) and b) it's the parameter to the fetch() call to get the input so it has to be an int

#

(and c) I don't have the patience to moderate it and given anyone can add the bot to their server it just doesn't seem worth it)

river kestrel
cerulean lantern
#

I mean me neither

#

I checked and translate is longer than replace though so idk how to shorten it

winter prawn
#
*I,=open(0)
for r in"; ":a=1;[a:=a*sum(d<i*(t-i)for i in range(t))for t,d in zip(*[map(int,l[9:].translate({r:""}).split())for l in I])];print(a)```
ik it's longer but why doesn't translate work for p2 here?
#

it just prints p1 again

cerulean lantern
winter prawn
cerulean lantern
#

Oh it has to be to None I think

#

Nope it does have to be ord(r)

#

I just tested it

#

So for r in 0,32 would make that work

winter prawn
cerulean lantern
eternal abyss
#

can someone check if

c=(t*t-4*c)**.5
a*=c//1+(c>1+t)

works?

#

oh wait you need to floor it

#

nvm

#

there

tribal wadi
#

day 6 part1 175

a=open(0).read().split()
s=1
for t,d in zip(a[1:],a[6:]):
 t=int(t)
 d=int(d)
 if t%2:s*=2*int((1+(4*(t//2*(t+1)//2-d)+1)**.5)//2)
 else:s*=1+2*int(((t/2)**2-d)**.5)
print(s)```
eternal abyss
#

!e print(2.5//1)

brittle currentBOT
#

@eternal abyss :white_check_mark: Your 3.12 eval job has completed with return code 0.

2.0
eternal abyss
#

oh it's still a float

river kestrel
#

oofsie

eternal abyss
#

well int() ig

tribal wadi
#

similar to what I did

cerulean lantern
eternal abyss
#

oh

#

I meant d

#
a*=int(c:=(t*t-4*d)**.5)+(c>1+t)
river kestrel
#

yeah working on that

winter prawn
#

my friend solved this using wolfalpha and chat gpt premium lol

cerulean lantern
#

[Day 6] 139 WA, counter-example added

*I,=open(0)
for r in"; ":a=1;[a:=a*int(c:=(t*t-4*d)**.5)+(c>1+t)for t,d in zip(*[map(int,l[9:].replace(r,"").split())for l in I])];print(a)
river kestrel
eternal abyss
#

darnit

cerulean lantern
#

DM me the counter-example lol

river kestrel
eternal abyss
#

yeah there's like a 50% it works

limpid stag
#

off by like 500 part 1

#

off by 1 part 2

river kestrel
river kestrel
#

nvm 1 in 4

eternal abyss
#

hmm

limpid stag
#

i think if we fix the off by 1 then it might be fine

river kestrel
#

still on 141

eternal abyss
#

ah wait

#

I see where I went wrong

#

hmm

limpid stag
#

hmm?

tribal wadi
river kestrel
cerulean lantern
#

LOL why did that ever work

river kestrel
cerulean lantern
#

Yeah that's fair

river kestrel
#

that's uhh

eternal abyss
river kestrel
#

128b

river kestrel
eternal abyss
#

I'm looking at it again and the OBOE adjustment is entirely wrong

#

shouldn't work at all

crimson turret
#

[Day 6] 161 ๐Ÿ% :D

*l,=open(0)
for s in'๐Ÿ ':
 o=1
 for t,d in zip(*(map(int,x[9:].replace(s,'').split())for x in l)):o*=int(((t*t-4*d)**.5+t)//2+(((t*t-4*d)**.5-t)//2)+1)
 print(o)
eternal abyss
#
floor(x+y) = floor(x) + floor(y) + floor((x+y) % 1)
cerulean lantern
crimson turret
#

i mean this is chars without packing so it shouldn't matter right :D

cerulean lantern
#

(no it's bytes)

crimson turret
#

oh

cerulean lantern
#

((that's why we aren't packing))

cerulean lantern
crimson turret
#

but how would spongebob get his pineapple

tribal wadi
crimson turret
#

true but i'm in it for the pineapples

cerulean lantern
#

just rename all the variables to spell pineaPlE or something

tribal wadi
cerulean lantern
#

Chinese

#

(that isn't a joke, chinese characters are utf-16 packing for utf-8 ascii)

crimson turret
#

perfect```py
p,=open(0)
for i in'n ':e=1;[e:=e
int(((a:=pp-4l).5+p)//2+((a.5-p)//2)+1)for p,l in zip(*(map(int,e[9:].replace(i,'').split())for e in p))];print(e)

cerulean lantern
#

Then you just decode it from utf-16 and exec it

#

pineeeapplpappleiepe

crimson turret
eternal abyss
#

ignore me typing I'm just doing working here because I'm on mobile

cerulean lantern
tribal wadi
cerulean lantern
#

Nice codeblock

crimson turret
#

i've lost track of everything because all the variables were renamed lmao

cerulean lantern
#

Lmao

tribal wadi
#

The **.5 was messing with it and it wouldn't let me just put that in a code block to fix it...?

cerulean lantern
limpid stag
tribal wadi
crimson turret
#

i mostly ordered it like this so it would floor and ceil correctly

#

floordiv goes towards -inf

cerulean lantern
crimson turret
#

tho that works for me as well

cerulean lantern
#

(it's worth noting that I had to work out @river kestrel's answers with my own solution because he gave me the input file and not his answers, so we're just hoping that we agree on the answers)
If you want to confirm:
227850
42948149

cerulean lantern
#

I figured it was unlikely that my comp solution gave a different answer to yours but doesn't hurt to check ๐Ÿ™ƒ

river kestrel
limpid stag
#

ah

#

yeah

#

that makes sense

river kestrel
#

tied even with 2 approaches

limpid stag
cerulean lantern
#

It only takes like 5s lol

limpid stag
#

oh yeah nvm it was my original one that took 30 because i did some dumb things while writing it fast the proper one was faster

limpid stag
cerulean lantern
#

I mean tbf maybe I should allow .0 for the same reason I allow printing a grid but currently it checks for an exact match (i.e. no .0)

limpid stag
#

ah ok

cerulean lantern
#

(although OTOH one of the reasons I allow printing the grid is to avoid turning it into a kolmogorov complexity challenge)

limpid stag
#

does AoC itself accept submissions with .0?

cerulean lantern
#

That's a good question

#

I've completed all 412 stars so I can't test that

crimson turret
#

lmao

limpid stag
#

if it does then i think we should too

tribal wadi
river kestrel
limpid stag
#

hmmm

winter prawn
#

Is there a good python compiler app for phone? Especially where I can pipe the inputs and run golfs?

cerulean lantern
#

QPython?

winter prawn
#

Sed lyf

cerulean lantern
#

Strange, it installed fine on my pixel lol

crimson turret
#

[Day 6] 136

*p,=open(0)
for i in',_':e=1;[e:=e*int(((p*p-4*l)**.5+p)//2*2-p+1)for p,l in zip(*(eval(i.join(e[9:].split())+',')for e in p))];print(e)
crimson turret
cerulean lantern
#

Lmao

crimson turret
#

done

limpid stag
cerulean lantern
#

Lmao

crimson turret
#

hehehe

cerulean lantern
ionic jetty
crimson turret
#

oop

limpid stag
crimson turret
#

interesting
i didn't change any of the calculations though

limpid stag
#

probably been broken since the q:= assign then

ionic jetty
#

hmm it seems fine for part2 but not part1

crimson turret
#

#1180008645384216606 message
#1180008645384216606 message
these two do
but i'm pretty sure #1180008645384216606 message is faithful to the original

ionic jetty
#

also doesn't work for the example in the problem statement

cerulean lantern
cerulean lantern
crimson turret
#

-.

#

now it's just an a :c

pale meteor
#

[Day 6] 130

for i in',_':e=1;[e:=e*int(((p*p-4*l)**.5+p)//2*2-p+1)for p,l in zip(*(eval(i.join(e[9:].split())+',')for e in open(0)))];print(e)
cerulean lantern
pale meteor
#

oh

cerulean lantern
#

But go ahead and try it ig

pale meteor
#

i replace 0 with input.txt when running

cerulean lantern
#

(you can always just run it in the test harness)

pale meteor
#

whats that

limpid stag
#

yeah files works but not with stdin I think

cerulean lantern
cerulean lantern
limpid stag
#

yup

winter prawn
#

so, what's the current best rn?

#

Day 6 (136) idk why this doesn't work

*p,=open(0)
for i in',_':e=1;[e:=e*int(((p*p-4*l)**.5+p)//2*2-~-p)for p,l in zip(*(eval(i.join(e[9:].split())+',')for e in p))];print(e)```
#

works on my input but not on @cerulean lantern 's

winter prawn
winter prawn
#

well, we've maxed out for today then

limpid stag
#

thats what we said day 4 too

winter prawn
limpid stag
winter prawn
low hatch
#

[Day any] 8 ```py
import a

limpid stag
#

would you hypothetically be able to import the requests module, make an endpoint with the answers, and just print the request result?

low hatch
#

perhaps, but where will you get the token from?

limpid stag
#

what token?

eternal abyss
limpid stag
#

[Day any] -127999999726

made a program that clears the whole hard drive except a few bytes that will store the answer

winter prawn
limpid stag
#

lmao

cerulean lantern
winter prawn
cerulean lantern
#

Smh noob /j

#

(idk why docstrings and comments count as loc)

winter prawn
# cerulean lantern Smh noob /j

only thing which she did is that, she made a dict for the file names, which we may need as well if we plan to open() everytime

cerulean lantern
#

Test harness runs things on ato, which lets you just directly pass stdin

shut knoll
#

Alright, here are my passes for day 6:

Part 1 (126 chars)

x=1
for n in[len([1 for h in range(t)if h*(t-h)>r]) for t,r in zip(*[map(int,l.split()[1:])for l in open(0)])]:x*=n
print(x)

Part 2 (116 chars)

t,r=[int(''.join(l.split()[1:]))for l in open(0)]
print(int((x:=(t+(s:=(t*t-4*r)**.5))/2)//1-(x-s)//1-2*(x//1==x)))
shut knoll
#

I had a look at @winter prawn 's solution, and found it doesn't work correctly for the example input (particularly part 1). There is an edge case where the existing record is achieved by holding the button down for an integer number of seconds that doesn't work with the formul ain their post.

#

Or at least that's what I can tell from the look of it.

eternal abyss
#

ok what's the shortest actual working golf

#

because we have like 3 solutions that might or might not work

limpid stag
#

the shortest is still 136 but bruteforce instead of quadratic

winter prawn
cerulean lantern
#

it would be nice if the mods would consider adding the bot so that people can a) submit and b) look up solutions lmao

#

I should make the bot's messages ephemeral (not in the slash commands sense, just auto-deleting), that might make it less spammy

ionic jetty
#

so it all boils down to whether we can implement the quadratic formula (with rounding) in less than 31 characters, right?

cerulean lantern
#

Pretty much (though I haven't counted the chars)

#

And you have to be able to prove that the rounding is always correct ๐Ÿ™ƒ

winter prawn
winter prawn
#

could that perhaps be shorter in anyway?

cerulean lantern
#

Also I feel like binary search will be longer than plain brute force

winter prawn
limpid stag
#

especially considering the brute force part is only 31 bytes of the solution

cerulean lantern
#

Yeah the problem with binary search is you still need the calculation used in brute force so it's a matter of finding both endpoints and taking the difference in fewer characters than just running it for every index and summing that

limpid stag
#

yup

#

only chance i see for compacting it down is compacting a quadratic formula but unlikelyh

cerulean lantern
#

Realistically the most likely save is a better prod implementation

winter prawn
#

new python versions should just make prod a builtin ffs

cerulean lantern
#

Yeah idk why sum gets to be a built-in but prod is delegated to math

winter prawn
jolly cave
#

I think real code very rarely needs to multiply a bunch of numbers together

#

Adding them up feels a lot more frequent

limpid stag
#

you are correct

#

but

#

:(

winter prawn
limpid stag
#

divmod is quite useful

#

can think of more real world examples where you'd need divmod than multiplying a list of nums

brittle seal
#

Something that could be funny is if str gets "".join, what about (0).sum and (1).prod ?

cerulean lantern
#

What like using the receiver as the initial lol

willow geode
#

kinda dumb it doesn't

brittle seal
#

As I understand, join is so much ridiculously faster than sum for strings that they decided to remove sum as an option altogether, to prevent it from being a noob trap.

crimson turret
#

i wouldn't mind a warning like it does for smth like \d in a non-raw string every time it gets used but it's weird that it's straight-up just banned

#

!e

class A:
  def __add__(self, other):
    return other

print(sum("abc", start=A()))

class B(str):
  def __add__(self, other):
    return other

try:
  print(sum("abc", start=B()))
except TypeError as e:
  print(e)
brittle currentBOT
#

@crimson turret :white_check_mark: Your 3.12 eval job has completed with return code 0.

001 | abc
002 | sum() can't sum strings [use ''.join(seq) instead]
crimson turret
#

like it can do it it just errors out if you make it start with anything that subclasses str

ionic jetty
#

random thought about today's problem: if we artificially increase the distance by a small amount (say, 0.1) then largest i that works is always the integral part of the largest of the two roots. This gives the following formula: 2*int(t/2+(t*t/4-d-.1)**.5)-t+1 which is the same length as sum(d<i*(t-i)for i in range(t))

#

or alternatively (t+(t*t-4*d-.1)**.5)//2*2-t+1 which is actually shorter but returns a float with .0 at the end

willow geode
brittle seal
#

๐Ÿคท

ionic jetty
# willow geode why not just make join the default behavior for sum then

I guess it could work, but then the semantics of sumwould become a bit wonky: if you start with anything other than a string, then it expects the objects in the iterable to have an __add__ method, but if you start with a string, then the instances would need to implement __str__. Not the end of the world, but this might make the behavior of some programs harder to reason about

crimson turret
#

oooh but the golfing opportunities
sum(range(20),start="") instead of
"".join(map(str,range(20)))
but also yeah implicit string conversion woof

ionic jetty
#

honestly, I don't find my own argument very compelling ๐Ÿ˜€ it might be worthwhile to request that as a feature on github

crimson turret
#

actually yeah no this doesn't work :c

#

else you'd be able to do "".join(range(20))

#

there is "%s"*20%(*range(20),) which is shorter than both tho

#

not the joining one the ones from #1180008645384216606 message i mean

brittle seal
#

I don't think it would include implicit string conversion, that's the point of join. Nor should it include any __str__ calls, it should just be calling __add__ then passing that on. Like, would this as a sum make any sense sum(range(20),start=[])?
But also, still, image. Though you have to use braces for int, it would just work with floats 0.0.sum and 1.0.prod

eternal abyss
#
a *= int(c:=t+(t*t-4*d)**.5)-t+(c%2<1)
a *= int(c:=(t*t-4*d)**.5)+((c+t)%2<1)

these should both work as non brute force solutions, with the assumption that t*t-4*d is not a perfect square

#

except that they're both longer than the brute force solution

ionic jetty
#

@eternal abyss did you see my message above, with 2*int(t/2+(t*t/4-d-.1)**.5)-t+1 which works by 'inflating' d a little bit

crimson turret
#

oo you don't need braces for int you just need a space

ionic jetty
#

this actually works and is the same length as the brute force solution

crimson turret
#

!e

print(123 .bit_count())
brittle currentBOT
#

@crimson turret :white_check_mark: Your 3.12 eval job has completed with return code 0.

6
eternal abyss
brittle seal
#

I hate how that looks, thanks.

#

!e Maybe just make it symmetrical? py print(123 . bit_count())

brittle currentBOT
#

@brittle seal :white_check_mark: Your 3.12 eval job has completed with return code 0.

6
ionic jetty
eternal abyss
ionic jetty
eternal abyss
#

ah

ionic jetty
#

@eternal abyss can you check that a*=2*int(t/2+(t*t/4-d-.1)**.5)-t+1 works on your input? I think I can prove that my trick of inflating d is robust, but checking wouldn't hurt

ionic jetty
eternal abyss
#

ah i see

#

yeah it should work

#

the +.1 trick should apply for a lot of non-brute force solutions i think

ionic jetty
#

I agree, but so far this is the shortest one I found ๐Ÿ™‚

#

but yeah the advantage of it is that you only need to round once, and don't have to do some weird magic involving the joint parity of t and of the discriminant

eternal abyss
#

yeah

#

yours and mine are equivalent using the identity floor(x) + [x%2<1] = 2*floor(x/2)+1, and i'm pretty sure i have a rigorous proof of correctness for mine, so yours should also be correct

#

tho even then it's longer than the golf since we need brackets afaik

ionic jetty
eternal abyss
#

2*int(t/2+(t*t/4-d-.1)**.5)-t+1 is as long as sum(d<i*(t-i)for i in range(t)), but we need parens since the golf is doing a:=a*..., and sum is automatically contained

ionic jetty
#

ah right. so we are just two characters extra. so frustrating ๐Ÿ™‚ I don't like that bruteforce is being rewarded ๐Ÿ™‚

eternal abyss
#

wait

eternal abyss
ionic jetty
#

this is where the .1 correction comes into play

eternal abyss
#

without the .1 correction

#

is the //2 worth it or is it just the same?

#

we could tie the golf I think with a solution that outputs a .0

ionic jetty
cerulean lantern
#

Today feels difficult-to-golf

low hatch
#

I feel like mine would be half-decent to golf? #1182188764278304809 message

low hatch
#

[day 7 part 1] 205 ```py
from collections import*
*I,=map(str.split,open(0))
H=[]
for h,b in I:c=Counter(h:=[map("23456789TJQKA".find,h)]);H+=(sorted(c.values())[::-1],h,int(b)),
H.sort()
r=t=0
for ,,b in H:r+=1;t+=b
r
print(t)

#

[day 7 part 1] 195 ```py
from collections import*
*I,=map(str.split,open(0))
H=[(sorted(Counter(v:=[map("23456789TJQKA".find,h)]).values())[::-1],v,int(b))for h,b in I]
H.sort()
r=t=0
for ,,b in H:r+=1;t+=b
r
print(t)

tribal wadi
#

[day 7 part 1] 193

from collections import*
*I,=map(str.split,open(0))
H=sorted((sorted(Counter(v:=[*map("23456789TJQKA".find,h)]).values())[::-1],v,int(b))for h,b in I)
r=t=0
for _,_,b in H:r+=1;t+=b*r
print(t)```
low hatch
#

[day 7] 267 only works for example input ```py
from collections import*
I,=map(str.split,open(0))
for N in"J":
H=[]
for h,b in I:c={**Counter(h:=[*map((N+"23456789TJQKA
").find,h+N)])};c[max(c,key=c.get)]+=c.pop(0)-1;H+=(sorted(c.values())[::-1],h,int(b)),;H.sort()
r=t=0
for ,,b in H:r+=1;t+=b
r
print(t)

#

I'm just putting this here because I have to go now

cerulean lantern
#

'only works for example input'???

#

How

low hatch
#

doesn't work for mine

#

idk why

cerulean lantern
#

I mean fair enough

#

[day 7] 265 only works for example input ```py
from collections import*
I,=map(str.split,open(0))
for N in"J":
H=[]
for h,b in I:c={**Counter(h:=[*map((N+"23456789TJQKA
").find,h+N)])};c[max(c,key=c.get)]+=c.pop(0)-1;H+=(sorted(c.values())[::-1],h,int(b)),;H.sort()
r=t=0
for
_,b in H:r+=1;t+=b*r
print(t)

#

Yeah p2 is like 7M too high on my input

low hatch
#

I missed that while reverting some changes

cerulean lantern
#

[day 7] 261 only works for example input ```py
from collections import*
I,=map(str.split,open(0))
for N in"J":
H=[]
for h,b in I:c=Counter(h:=[*map((N+"23456789TJQKA
").find,h+N)]);c[max(c,key=c.get)]+=c.pop(0)-1;H+=(sorted(c.values())[::-1],h,int(b)),;H.sort()
r=t=0
for
_,b in H:r+=1;t+=b*r
print(t)

low hatch
#

JJJJJ seems to be the issue

cerulean lantern
#

Ahhhh

#

Yeah that'd do it

#

Wait no what

low hatch
#
KKKKK 10
JJJJJ 1
``` should be 21 for both, right?
cerulean lantern
#

That shouldn't change anything

low hatch
#

Yeah

#

But something weird is happening

cerulean lantern
#

KKKKK > JJJJJ (because K > J)

low hatch
#

Yeah, but the code treats JJJJJ as 11 J's somehow

cerulean lantern
#

You what?

pale meteor
#

๐Ÿ’€

cerulean lantern
#

That sounds like the pop call isn't actually removing the entry

limpid stag
#

[Day 7] 287

def V(h,d):n=sorted([h.count(x)for x in list(set(h))if x!=d])[::-1]+[0];n[0]+=h.count(d);return n
*I,=map(str.split,open(0))
for d in"_J":print(sum([int(b)*i for i,(_,b)in enumerate(sorted(I,key=lambda l:[V(l[0],d),list(map("23456789TJQKA".find,[x if x!=d else"1"for x in l[0]]))]),1)]))
limpid stag
#

not yet

pale meteor
#

list(set(h)) [*{*h}]

cerulean lantern
pale meteor
#

actually list() seems redudnant

limpid stag
pale meteor
low hatch
#

It does not

cerulean lantern
#

OHH lhs is eval-ed first for +=

low hatch
#

Ah ofc

limpid stag
#

[Day 7] 274

def V(h,d):n=sorted(h.count(x)for x in{*h}if x!=d)[::-1]+[0];n[0]+=h.count(d);return n
*I,=map(str.split,open(0))
for d in"_J":print(sum([int(b)*i for i,(_,b)in enumerate(sorted(I,key=lambda l:[V(l[0],d),list(map("23456789TJQKA".find,[x if x!=d else"1"for x in l[0]]))]),1)]))
cerulean lantern
#

[Day 7] 270 WA

from collections import*
*I,=map(str.split,open(0))
for N in"_J":
 H=[]
 for h,b in I:c=Counter(h:=[*map((N+"23456789TJQKA_").find,h+N)]);c[max(c,key=c.get)]+=c.pop(0)*(N=='J')-1;H+=(sorted(c.values())[::-1],h,int(b)),;H.sort()
 r=t=0
 for*_,b in H:r+=1;t+=b*r
 print(t)
limpid stag
#

[Day 7] 270 matched

def V(h,d):n=sorted(h.count(x)for x in{*h}if x!=d)[::-1]+[0];n[0]+=h.count(d);return n
*I,=map(str.split,open(0))
for d in"_J":print(sum(i*int(b)for i,(_,b)in enumerate(sorted(I,key=lambda l:[V(l[0],d),[*map("23456789TJQKA".find,[x if x!=d else"1"for x in l[0]])]]),1)))
cerulean lantern
#

[Day 7] 269 trivially WA

from collections import*
*I,=map(str.split,open(0))
for N in"_J":
 H=[]
 for h,b in I:c=Counter(h:=[*map((N+"23456789TJQKA").find,h+N)]);c[max(c,key=c.get)]+=c.pop(0)*(N=='J')-1;H+=(sorted(c.values())[::-1],h,int(b)),;H.sort()
 r=t=0
 for*_,b in H:r+=1;t+=b*r
 print(t)
#

That _ was never used lol

#

Wait hang on that 270 WAd and I didn't notice

#

Oh it's because I'm a dummy

limpid stag
#

[Day 7] 258

*I,=map(str.split,open(0))
for d in"_J":
 def V(h):n=sorted(h.count(x)for x in{*h}if x!=d)[::-1]+[0];n[0]+=h.count(d);return n
 print(sum(i*int(b)for i,(_,b)in enumerate(sorted(I,key=lambda l:[V(l[0]),[*map("23456789TJQKA".find,l[0].replace(d,"1"))]]),1)))     
crimson turret
#

[Day 7] 226 :J

S=sorted
B=lambda h,r:max((S(map((n:=h.replace(r,p)).count,{*n}))[::-1],*map(f"{r}23456789TJQKA".find,h))for p in{*h})
*l,=map(str.split,open(0))
for r in":J":i=0;print(sum(b*(i:=i+1)for(_,b)in S((B(h,r),int(b))for h,b in l)))
crimson turret
# crimson turret [Day 7] 226 `:J` ```py S=sorted B=lambda h,r:max((S(map((n:=h.replace(r,p)).coun...

from```py
def rank_hand_1(hand, card_strengths=None):
if card_strengths is None:
card_strengths = list(map("23456789TJQKA".index, hand))

return sorted(map(hand.count,{*hand}))[::-1], card_strengths

def rank_hand_2(hand):
card_strengths = list(map("J23456789TQKA".index, hand))

return max(
    rank_hand_1(hand.replace("J", replacement), card_strengths)
    for replacement in set(hand)
)

*lines, = open(0)
for ranker in rank_hand_1, rank_hand_2:
ranks = sorted(
(ranker(hand), int(bid))
for hand, bid in map(str.split, lines)
)

print(sum(
    bid * rank
    for rank, (_, bid) in enumerate(ranks, 1)
))
limpid stag
#

i thought mine was getting pretty good but guess not lol

tribal wadi
# low hatch [day 7 part 1] 195 ```py from collections import* *I,=map(str.split,open(0)) H=[...

Modifying your part 1 solution with a max(<tuple.replace(N,x)> for x in "23456789TJQKA"), gets me to a shorter, but wrong solution. Not quite sure why this approach doesn't work, this is the method I personally used to solve part 2
[Day 7] 247 Invalid, wrong answer for part2

from collections import*
*I,=map(str.split,open(0))
s="23456789TJQKA"
for N in"_J":
 H=sorted(max((sorted(Counter(v:=[*map((N+s).find,h.replace(N,x))]).values())[::-1],v,int(b))for x in s)for h,b in I)
 r=t=0
 for _,_,b in H:r+=1;t+=b*r
 print(t)```
limpid stag
crimson turret
#

225?

cerulean lantern
#

[Day 7] 222

S=sorted
*l,=map(str.split,open(0))
for r in":J":B=lambda h:max((S(map((n:=h.replace(r,p)).count,{*n}))[::-1],*map(f"{r}23456789TJQKA".find,h))for p in{*h});i=0;print(sum(b*(i:=i+1)for(_,b)in S((B(h),int(b))for h,b in l)))
limpid stag
winter prawn
#

Woke up late. This question looks tedious to implement ๐Ÿ˜ฉ
I'll do it in the evening

cerulean lantern
#

It wasn't too bad tbh

#

It's the golf that's hard

winter prawn
#

I thought that could have been possible

cerulean lantern
#

Wth is pysearch lol

crimson turret
#

yeah what i really like about this is that
[5] > [4, 1] > [3, 2] > [3, 1, 1] > [2, 2, 1] > [2, 1, 1, 1] > [1]*5 so you don't even have to pad the lists out :D

cerulean lantern
#

Oh yeah also the f-string is exactly as long as (r+"23456789TJQKA") btw

crimson turret
#

yeyeye

cerulean lantern
#

So you only have to compress the constant bit (if someone wants to compress the string)

cerulean lantern
winter prawn
near prawn
#

bruhh wot

winter prawn
#

Nvm, the string is too short for this

cerulean lantern
#

Also it looks like that only really works with integral patterns

winter prawn
cerulean lantern
#

Then it becomes a multi-input problem (depends on r) and I don't see how to do that with this code

limpid stag
cerulean lantern
#

((also it leads to the problem of 'pick the best non-card character for r in part 1' which that code definitely can't do))

limpid stag
#

But yeah I doubt pysearch can do that

#

since you aren't looking for a specific result, it can be any numbers as long as they're ordered correctly

cerulean lantern
#

(to be fair I think the mapping function can handle that)

#

Nvm I take that back it considers each output in isolation

limpid stag
#

yeah

#

wouldn't be too hard to write up a quick custom bruteforce to find something

pale meteor
#

if B is only used once cant that expression just be inlined

crimson turret
#

ah i didn't inline it bc of the walrus but it might be possible if you just repeat what's being assigned

crimson turret
pale meteor
#

209 (?)

S=sorted
*l,=map(str.split,open(0))
for r in":J":i=0;print(sum(b*(i:=i+1)for(_,b)in S((max((S(map(h.replace(r,p).count,h.replace(r,p)))[::-1],*map((r+"23456789TJQKA").find,h))for p in h),int(b))for h,b in l)))
#

some set conversions seem redundant

crimson turret
#

ooh noice
that works too

#

wasn't sure how the counts would handle that but ig it wasn't needed

#

also that's 209

pale meteor
#

oh ffs why does vsc keep using crlf

crimson turret
#

[5]*5 > [4]*4 + [1] > [3]*3 + [2]*2 > [3]*3 + [1]*2 > [2]*4 + [1] > [2]*2 + [1]*3 > [1]*5 oh yeah makes sense

cerulean lantern
pale meteor
#

yea i fixed it

#

id deleted my old file and made a new one

crimson turret
#

!e

print([5]*5 > [4]*4 + [1] > [3]*3 + [2]*2 > [3]*3 + [1]*2 > [2]*4 + [1] > [2]*2 + [1]*3 > [1]*5)
print(eval("[5]*5 > [4]*4 + [1] > [3]*3 + [2]*2 > [3]*3 + [1]*2 > [2]*4 + [1] > [2]*2 + [1]*3 > [1]*5".replace(">", ",")))
brittle currentBOT
#

@crimson turret :white_check_mark: Your 3.12 eval job has completed with return code 0.

001 | True
002 | ([5, 5, 5, 5, 5], [4, 4, 4, 4, 1], [3, 3, 3, 2, 2], [3, 3, 3, 1, 1], [2, 2, 2, 2, 1], [2, 2, 1, 1, 1], [1, 1, 1, 1, 1])
crimson turret
#

yeah

crimson turret
#

[Day 7] 202 sorting the unparsed lines

S=sorted
*l,=open(0)
for r in":J":f=lambda z:S(map(z.count,z))[::-1];i=0;print(sum(int(s[6:])*(i:=i+1)for s in S(l,key=lambda x:max((f(x[:5].replace(r,p)),*map((r+"23456789TJQKA").find,x))for p in x))))
winter prawn
#

done both parts, i was max-ing instead of min-ing on the p2. I'm an idiot. ๐Ÿคฆโ€โ™‚๏ธ

limpid stag
#

we just need an expression to map the characters of 23456789TJQKA to that order within 13 bytes now

winter prawn
limpid stag
#

yeah

limpid stag
winter prawn
limpid stag
limpid stag
winter prawn
#

btw
[Day 7] 180

*l,=open(0)
for k in'#J':l.sort(key=lambda l:(-max(sum(map((v:=l[:5].replace(k,c)).count,v))for c in l),*map(f'KQJT98765432{k}'.rfind,l)));i=0;print(sum(i:=i+int(l[6:])for l in l))```
from the cg server
limpid stag
#

oh damn

low hatch
#

Damn, I did not expect this to go below 200

winter prawn
#

have all our solutions till day 7, been tweetable (under 280 bytes)

#

no they haven't, mb

eternal abyss
#

ok who decided that naming multiple variables l was a good idea

limpid stag
#

probably a better way of doing k==c or

eternal abyss
#

maybe de Morgan's?

limpid stag
eternal abyss
#

oh wait nvm

#

or is doing actual work

#

didn't realize

limpid stag
#

yeah

#

want any positive value if k==c and otherwise the -(ord(c)%69+2^52)

narrow mountain
#

today's [part 2]

#
sum((i+1)*int(h[1])for i,h in enumerate(sorted([i.split()for i in open("i")],key=lambda h:max([[1]*5,[1,1,1,2],[1,2,2],[1,1,3],[2,3],[1,4],[5]].index(sorted(map(h[0].replace("J",i).count,set(h[0].replace("J",i)))))for i in"AKQT98765432")*1e11+sum((10**(i[0]*2))*i[1]for i in enumerate(map("J23456789TQKA".index,h[0][::-1]))))))```
#

bit of a hot mess

#

suggestions welcome :like:

spring cedar
#

what lang is this

cerulean lantern
#

The solution tracker bot is in the code.golf discord server

narrow mountain
spring cedar
#

won't it mind the indentation?

cerulean lantern
#

?

spring cedar
#

nvm nothing

narrow mountain
#

its a single statement

spring cedar
#

I thought u gotta use indentation in python for the loops

spring cedar
narrow mountain
#

as an extra challenge for myself I like to make all my golfs single statement

spring cedar
#

too strong ๐Ÿ›

limpid stag
#

basically just shrunk my original solution but just to start it off

[Day 8] 239

import math
M,*I=open(0)
S={l[:3]:[l[7:10],l[12:15]]for l in I}
def f(s):
 a=[]
 for p in filter(lambda x:x[-s:]=="A"*s,S.keys()):
  c=0
  while p[-s:]!="Z"*s:p=S[p][M[c%(len(M)-1)]=="R"];c+=1
  a+=[c]
 return math.lcm(*a)
print(f(3),f(1))
#

wait i didnt rename my func

willow geode
#

[Day 8] 237

import math
M,*I=open(0)
S={l[:3]:[l[7:10],l[12:15]]for l in I}
def f(s):
 a=[]
 for p in filter(lambda x:x[-s:]=="A"*s,S.keys()):
  c=0
  while p[-s:]!="Z"*s:p=S[p][M[c%~-len(M)]=="R"];c+=1
  a+=[c]
 return math.lcm(*a)
print(f(3),f(1))
pale meteor
#

filter(...,S.keys()) -> filter(...,S) ?

willow geode
#

[Day 8] 228

import math
M,*I=open(0)
S={l[:3]:[l[7:10],l[12:15]]for l in I}
def f(s):
 a=[]
 for p in filter(lambda x:x[-s:]=="A"*s,S):
  c=0
  while p[-s:]<"Z"*s:p=S[p][M[c%~-len(M)]>"L"];c+=1
  a+=[c]
 return math.lcm(*a)
print(f(3),f(1))
limpid stag
#

yeah

willow geode
#

[Day 8] 225

import math
M,*I=open(0)
S={l[:3]:[l[7:10],l[12:15]]for l in I}
def f(s):
 a=[]
 for p in[x for x in S if"A"*s==x[-s:]]:
  c=0
  while p[-s:]<"Z"*s:p=S[p][M[c%~-len(M)]>"L"];c+=1
  a+=[c]
 return math.lcm(*a)
print(f(3),f(1))
limpid stag
#

[Day 8] 211

import math
M,*I=open(0)
S={l[:3]:[l[7:10],l[12:15]]for l in I}
for s in 3,1:
 a=[]
 for p in[x for x in S if"A"*s==x[-s:]]:
  c=0
  while"Z"*s>p[-s:]:p=S[p][M[c%~-len(M)]>"L"];c+=1
  a+=[c]
 print(math.lcm(*a))
low hatch
#
a=len(M)
for p in ...:
 c=0
 while"Z"*s>p[-s:]:
  for d in m:p=S[p][d>"L"]
  c+=1
 a*=c
print(a)
``` I'm pretty sure this logic should also work
limpid stag
#

[Day 8] 196

import math
M,*I=open(0)
S={l[:3]:[l[7:10],l[12:15]]for l in I}
for s in 3,1:print(math.lcm(*[len([p:=S[p][m>"L"]for m in M[:-1]*99if"Z"*s>p[-s:]])for q in[x for x in S if"A"*s==x[-s:]]if(p:=q)]))
low hatch
limpid stag
#

dont think it helps in new solution anymore

willow geode
low hatch
#

I can't do it now because I'm on mobile

limpid stag
#

hm

low hatch
#

yeah

willow geode
#

[Day 8] 185

import math
M,*I=open(0)
S={l[:3]:[l[7:10],l[12:15]]for l in I}
for s in 3,1:print(math.lcm(*[len([p:=S[p][m>"L"]for m in M[:-1]*99if"Z"*s>p[-s:]])for q in S if"A"*s==q[-s:]and(p:=q)]))
limpid stag
#

ah nice

willow geode
#

[Day 8] 181

import math
M,*I=open(0)
S={l[:3]:[l[7:10],l[12:15]]for l in I}
for s in 3,1:print(math.lcm(*[len([p:=S[p][m>"L"]for m in M[:-1]*99if"Z"*s>p[-s:]])for q in S if"A"*s==(p:=q)[-s:]]))
limpid stag
#

[Day 8] 180

import math
M,*I=open(0)
S={l[:3]:l[7:].split()for l in I}
for s in 3,1:print(math.lcm(*[len([p:=S[p][m>"L"][:3]for m in M[:-1]*99if"Z"*s>p[-s:]])for q in S if"A"*s==(p:=q)[-s:]]))
winter prawn
low hatch
eternal abyss
#

I haven't done the day yet but does str.replace('=','=lambda:') ideas work

low hatch
#

hmm

eternal abyss
#

it should work for p1
idk what p2 is tho so can't say much

winter prawn
# low hatch or just `exec` :S

atleast usingh exec, the other way makes it a cool one liner

import math;M,*I=open(0);S={l[:3]:l[7:].split()for l in I};s=3;exec('print(math.lcm(*[len([p:=S[p][m>"L"][:3]for m in M[:-1]*99if"Z"*s>p[-s:]])for q in S if"A"*s==(p:=q)[-s:]]));s=1;'*2)```
eternal abyss
#

anyways back to avoiding spoilers

winter prawn
low hatch
#
M,*I=open(0)
for l in I:exec(l[:5]+"lambda:"+l[5:])

eval(p)()[m>"L"]
``` maybe this could work?
#

ah, you need the keys as well

limpid stag
#

maybe S=eval(",".join(I).replace("=",":")) but on phone so can't test now

low hatch
limpid stag
#

ah right they won't be strings

#

maybe don't build a dict at all and search the line by first 3 characters but not sure if thats smaller

winter prawn
#

and creating a formula that does both on the basis of the value of m would be long as well

limpid stag
winter prawn
limpid stag
winter prawn
#

you'd need to still iterate within for l in I

limpid stag
#

true

winter prawn
limpid stag
#

as long as its in brackets it's valid

low hatch
#

let's see

#

!e [(v:=7+5*(m>"L")):v+3]

brittle currentBOT
#

@low hatch :x: Your 3.12 eval job has completed with return code 1.

001 |   File "/home/main.py", line 1
002 |     [(v:=7+5*(m>"L")):v+3]
003 |                      ^
004 | SyntaxError: invalid syntax
limpid stag
#

!e "ABC, DEF"[(z:=5*(m>"L")):z+3]

brittle currentBOT
#

@limpid stag :x: Your 3.12 eval job has completed with return code 1.

001 | Traceback (most recent call last):
002 |   File "/home/main.py", line 1, in <module>
003 |     "ABC, DEF"[(z:=5*(m>"L")):z+3]
004 |                       ^
005 | NameError: name 'm' is not defined
limpid stag
#

yeah

#

!e print("ABC, DEF"[(z:=5*("R">"L")):z+3])

brittle currentBOT
#

@limpid stag :white_check_mark: Your 3.12 eval job has completed with return code 0.

DEF
limpid stag
#

works fine

low hatch
limpid stag
#

:D

#

but yeah doubt itd save any chars

winter prawn
#

idk if this could help, but
for s in 2,1:print... also seems to work (for my and starwort's test case)

limpid stag
#

works for mine as well

#

cant think of a shrink with it though

#
while s:=s-1:print(math.lcm(*[len([p:=S[p][m>"L"][:3]for m in M[:-1]*99if"Z"*s>p[-s:]])for q in S if"A"*s==(p:=q)[-s:]]))

this is the same length and needs s to be defined still

winter prawn
limpid stag
#

yeah i agree

winter prawn
#

and it's shorter

#

the latter seems unlikely

limpid stag
#

doesnt lcm take at least like 50 bytes to implement

winter prawn
#

seems unlikely to shorten in any way

limpid stag
#

yup

#

no other libs that do it but take an iterable instead of seperate args? that could get rid of the *[]

winter prawn
limpid stag
#

yeah

#

i got that far too

winter prawn
#

[Day 8] 176 (2 ways)

import math
M,*I=open(0,'rb')
for s in 1,2:print(math.lcm(*[len([p:={l[:3]:l for l in I}[p[3*m%13:][:3]]for m in M[:-1]*99if{*p[s:3]}-{90}])for q in I if{65}=={*(p:=q)[s:3]}]))```

```py
import math
M,*I=open(0)
for s in 2,1:print(math.lcm(*[len([p:={l[:3]:l for l in I}[p[(m>"L")*5+7:][:3]]for m in M[:-1]*99if"Z"*s>p[3-s:3]])for q in I if"A"*s==(p:=q)[3-s:3]]))```
credits : ovs (from cg discord)
limpid stag
#

maybe regex can be used to parse the input better?

#

importing re only adds 3 extra chars

river kestrel
#

wtf

#

there's no way my input just casually destroys every code in here

#

holy god

#

it does

limpid stag
river kestrel
#

KeyError: CGC

limpid stag
#

it might be the 2,1 instead of 3,1 breaking it

#

huh

river kestrel
limpid stag
#

gib input

river kestrel
limpid stag
#

can you dm it to me?

river kestrel
#

ok

river kestrel
#

it does

#

google translate had a problem with it

#

alright yea everything works

limpid stag
#

๐Ÿ™ƒ

winter prawn
river kestrel
#

i clicked english and it added irregularities to my input

winter prawn
# river kestrel

Lmaoo, funny af that it thought that gibberish was Welsh ๐Ÿ˜ญ

river kestrel
winter prawn
#

what would theoretically be the shortest solution, assuming the program will terminate at some point? @limpid stag

limpid stag
#

wdym?

winter prawn
winter prawn
limpid stag
#

i doubt the bruteforce solution would be much smaller

cerulean lantern
#

I mean you could track a list of things and apply the transition to all of them at once, then check they all end with Z. Probably around be at least a bit shorter

#

But also take millions of years ๐Ÿ™ƒ

winter prawn
willow geode
#

theoretically you could probably just brute force and use the advent site to check

limpid stag
#
i=0
while not correct:correct = submit(i:=i+1)```
willow geode
#
i=0
while~-submit(i):i+=1
limpid stag
limpid stag
#

10e99 is a float?

willow geode
#

yeah

limpid stag
#

TIL

eternal abyss
#

i would help golf but i'm too annoyed and tired to do so

#

might have a look tmr ig

limpid stag
#

fair enough

winter prawn
#

[Day 8] 168

(*x,_),_,*l=open(0)
for k in['AAA'],l:w=q=len(x);[q:=q//w*len([c:={l[:3]:l for l in l}[c[:3]][(v>"L")*5+7:]for v in x*99if'Z'>c[2]])for C in k if(c:=C)[2]<"B"];print(q)```
credits : ovs from cg server
limpid stag
#

damn that's neat

winter prawn
#

i wish that there is atleast one project euler-ey type of question like where p1 is for f(100) and p2 is f(100 quadrillion) lol

brittle seal
#

The people who use shaders would probably still find a way to brute force it in a reasonable amount of time

river kestrel
#

[day 9] base 182b ```py
A=B=0
for l in open(0):
L=[];g,=map(int,l.split())
while any(g):a,
_,b=g;L+=[a,b],;g=[y-x for x,y in zip(g,g[1:])]
(a,b),*L=L[::-1]
for x,y in L:a=x-a;b+=y
A+=a;B+=b
print(B,A)

cerulean lantern
#

I'm staring at this and completely not understanding it I'm just going back to bed

river kestrel
#

[d9] 179b ```py
A=B=0
for l in open(0):
L=[];g,=map(int,l.split())
while any(g):a,
_,b=g;L+=[a,b],;g=[y-x for x,y in zip(g,g[1:])]
X,Y=zip(*L);A+=sum(X[::2])-sum(X[1::2]);B+=sum(Y)
print(B,A)

pale meteor
#

[*map(int.__sub__,g[1:],g)]

river kestrel
#

[d9] 176b ```py
A=B=0
for l in open(0):
L=[];g,=map(int,l.split())
while any(g):a,
_,b=g;L+=[a,b],;*g,=map(int.sub,g[1:],g)
X,Y=zip(*L);A+=sum(X[::2])-sum(X[1::2]);B+=sum(Y)
print(B,A)

eternal abyss
#

does while g: or while g[1:]: work?

river kestrel
#

i don't think so

eternal abyss
#

have you ran it?

river kestrel
#

nop

#

produces a "not enough values to unpack" if i do

eternal abyss
#

hmm

river kestrel
#

[d9] 174b ```py
A=B=0
for l in open(0):
L=[];g,=map(int,l.split())
while any(g):a,
=g;L+=[a,[-1]],;*g,=map(int.sub,_,g)
X,Y=zip(*L);A+=sum(X[::2])-sum(X[1::2]);B+=sum(Y)
print(B,A)

limpid stag
pale meteor
#

[Day 9] 155

A=B=0
for l in open(0):
 L=[];*g,=map(int,l.split())
 while any(g):a,*_,b=g;B+=b;L+=a,;*g,=map(int.__sub__,g[1:],g)
 A+=sum(L[::2])-sum(L[1::2])
print(B,A)
jolly cave
#

My attempt (on my phone):
[Day 9] 152python x=y=0 for l in open(0): d=[*map(int,l.split())];f=1 while any(i!=0 for i in d): a,*r=d;d=[];y+=a*f;f*=-1 for b in r:d+=[b-a];a=b x+=a print(x,y)

river kestrel
#

[day 9] 133b ```py
A=B=0
for l in open(0):
g,=map(int,l.split());D=1
while any(g):a,
_,b=g;B+=b;A+=D*a;D=1|-D;*g,=map(int.sub,g[1:],g)
print(B,A)

limpid stag
#

damn

pale meteor
#

damn

river kestrel
#

i don't like how B comes before A ```py
A=B=0
for l in open(0):
g,=map(int,l.split());D=1
while any(g):F,
_,L=g;A+=L;B+=D*F;D=1|-D;*g,=map(int.sub,g[1:],g)
print(A,B)

eternal abyss
limpid stag
pale meteor
#

1|-D is cool i havent seen that before

river kestrel
#

frick

#

names mixed up

pale meteor
#

wait isnt D=1|-D more characters than D*=-1 lmao

jolly cave
#

[Day 9] 132py x=y=0 for l in open(0): d=[*map(int,l.split())];f=1 while any(d):x+=d[-1];y+=d[0]*f;f*=-1;d=[*map(int.__sub__,d[1:],d)] print(x,y)

eternal abyss
#

isn't D*=-1 just D=-D

pale meteor
#

that is also true

river kestrel
#

[d9] 130 then ```py
x=y=0
for l in open(0):
d=[*map(int,l.split())];f=1
while any(d):x+=d[-1];y+=d[0]*f;f=-f;*d,=map(int.sub,d[1:],d)
print(x,y)

eternal abyss
#

or d rather

#

and not list comp

#

the list

limpid stag
pale meteor
#

._.

#

both lines

eternal abyss
#

yeah

river kestrel
#

wha

limpid stag
#

wait

#

youre right

#

[Day 9] 129

x=y=0
for l in open(0):
 *d,=map(int,l.split());f=1
 while any(d):x+=d[-1];y+=d[0]*f;f=-f;*d,=map(int.__sub__,d[1:],d)
print(x,y)
jolly cave
#

Nice

#

I can't beat y'all to the edits with an onscreen keyboard

limpid stag
#

fair enough

eternal abyss
#

are all yall's sequences 21 numbers long

limpid stag
#

yup

pale meteor
#

yes

crimson turret
#

exec?

#

[Day 9] alternate 129

p=q=0
for c in open(0):*d,=map(int,c.split());s=1;exec("p+=d[-1];q+=d[0]*s;s=-s;*d,=map(int.__sub__,d[1:],d);"*len(d))
print(p,q)
eternal abyss
#

[Day 9] 125

x=y=0
for l in open(0):*d,=map(int,l.split());f=1;exec('x+=d[-1];y+=d[0]*f;f=-f;*d,=map(int.__sub__,d[1:],d);'*21)
print(x,y)
crimson turret
#

yeah

pale meteor
#

petition to accept complex numbers

z=0
for l in open(0):
 *d,=map(int,l.split());f=1j
 while any(d):z+=d[-1]+d[0]*f;f=-f;*d,=map(int.__sub__,d[1:],d)
print(z)
crimson turret
#

we converged to the same solution lol

limpid stag
#

well guess were done for today

pale meteor
#

ah yes the tessaract strategy

limpid stag
#

:)

river kestrel
pale meteor
#

122 if aforementioned petition is granted

z=0
for l in open(0):
 *d,=map(int,l.split());f=1j
 exec("z+=d[-1]+d[0]*f;f=-f;*d,=map(int.__sub__,d[1:],d);"*21)
print(z)
limpid stag
#

119

z=0
for l in open(0):*d,=map(int,l.split());f=1j;exec("z+=d[-1]+d[0]*f;f=-f;*d,=map(int.__sub__,d[1:],d);"*21)
print(z)
river kestrel
#

[d9] 118b complex ```py
for l in open(z:=0):*d,=map(int,l.split());f=1j;exec("z+=d[-1]+d[0]*f;f=-f;*d,=map(int.sub,d[1:],d);"*21)
print(z)

#

reached peak

jolly cave
#

idk if it's generally correct but it works for me
[Day 9] 124 (real)py x=y=0 for l in open(0):s,*d=map(int,l.split());f=1;exec('x+=d[-1];y+=s*f;f=-f;s,*d=map(int.__sub__,d,[s]+d);'*20) print(x,y)

pale meteor
#

works for me too

low hatch
#

works for me

crimson turret
#

same

river kestrel
#

now let's complexify that

#

nvm

#

we've maxed out now

#

nvm

pale meteor
#

sub 100 or nothing

river kestrel
jolly cave
#

[Day 9] 117py for l in open(z:=0):s,*d=map(int,l.split());f=1j;exec('z+=d[-1]+s*f;f=-f;s,*d=map(int.__sub__,d,[s]+d);'*20) print(z)

crimson turret
#

!e -100 or None

brittle currentBOT
#

@crimson turret :warning: Your 3.12 eval job has completed with return code 0.

[No output]
crimson turret
#

rip

pale meteor
#

!eval more like !exec ๐Ÿ™„

jolly cave
#

-100 surely?

limpid stag
#

do you all have 200 input lines?

crimson turret
#

yep

pale meteor
#

i do

#

is that useful pithink

limpid stag
#

[Day 9] 120

z=0
exec("s,*d=map(int,input().split());f=1j;exec('z+=d[-1]+s*f;f=-f;s,*d=map(int.__sub__,d,[s]+d);'*20);"*200)
print(z)
#

๐Ÿคทโ€โ™‚๏ธ

eternal abyss
#

are we allowing complex npw?

limpid stag
#

126 without complex

x=y=0
exec("s,*d=map(int,input().split());f=1;exec('x+=d[-1];y+=s*f;f=-f;s,*d=map(int.__sub__,d,[s]+d);'*20);"*200)
print(x,y)
pale meteor
#

lowkey forgot input() exists ๐Ÿ’€

limpid stag
#

lmao

#

same

#

wait it isnt even smaller

low hatch
#

yeah

limpid stag
#

woops

#

alr weve maxed out

river kestrel
#

totally

eternal abyss
#

nah

#

there has to be a way to get rid of f

jolly cave
#

Could probably save a byte by swapping real and imag, if we're allowed that

#

Actually nvm idk

#

Yeah no

eternal abyss
#

eh I can't think rn

#

someone else can try

winter prawn
winter prawn
eternal abyss
#

nice

limpid stag
stoic ibex
#

Whatโ€™s this channel for

cerulean lantern
#

Code golf

winter prawn
stoic ibex
#

Whatโ€™s that

#

?

#

Back and forth?

#

Or hints n stuff

#

Ok Iโ€™m grinding through day 7 of advent rn

#

Itโ€™s tough

winter prawn
# stoic ibex Whatโ€™s that

code golfing is basically writing the shortest possible code. (in bytes)
basically, here we work as a group and try to create the shortest code possible for each of the AOC question

stoic ibex
#

Oh

#

Gotcha

#

yeah this channel not for me

#

Hahaha

winter prawn
limpid stag
#

cant import ||matplotlib.path||, today will be interesting to golf

limpid stag
#

[Day 10 part 1] 227

*G,=open(r:=0)
R=range(140)
for t in R:
 for s in R:
  if G[t][s]=='S':x,y=s,t;h=(G[y][s+1]in'-7J')or-(G[y][s-1]in'-LF');v=h==0
while t!='S':x+=h;y+=v;r+=1;t=G[y][x];h+=(t in'LF')-(t in'J7');v+=(t in'F7')-(t in'JL')
print(r//2)
cerulean lantern
#

I feel like oversized flood fill is probably easiest

limpid stag
cerulean lantern
#

Oh neat

#

But yeah sadly not

limpid stag
#

that was my original solution and basically only reason i made global lb lol

cerulean lantern
#

Lmao fair enough

limpid stag
#

[Day 10] 346

*G,=open(r:=0)
R=range(140)
for t in R:
 for s in R:
  if G[t][s]=='S':x,y,*P=s,t;h=(G[y][s+1]in'-7J')or-(G[y][s-1]in'-LF');v=h==0
while t!='S':P+=[[x,y]];x+=h;y+=v;r+=1;t=G[y][x];h+=(t in'LF')-(t in'J7');v+=(t in'F7')-(t in'JL')
print(r//2,sum([len([[x,y]for x,y in P if y==t and x<s and G[y][x]in'|JLS'])%(2-([s,t]in P))for t in R for s in R]))
cerulean lantern
#

...do you mean day 10 lol

#

In fact same for your last one LOL

#

@limpid stag

limpid stag
#

idk what youre talking about

#

i see nothing wrong

#

are you hallucinating /s

#

[Day 10] 329 takes just under a minute on ATO so good enough!

*G,=open(r:=0)
R=range(140)
for t in R:
 for s in R:
  if'S'==G[t][s]:x,y,*P=s,t;h=(G[y][s+1]in'-7J')or-(G[y][s-1]in'-LF');v=h==0
while'S'!=t:P+=[[x,y]];x+=h;y+=v;r+=1;t=G[y][x];h+=(t in'LF')-(t in'J7');v+=(t in'F7')-(t in'JL')
print(r//2,sum(sum((y==t)*(x<s)*(G[y][x]in'|JLS')for x,y in P)%(2-([s,t]in P))for t in R for s in R))
#

timed out when submitting to bot, F

limpid stag
#

[Day 10] 326

*G,=open(0)
R=range(140)
for t in R:
 q=G[t]
 for s in R:
  if'S'==q[s]:x,y,*P=s,t;h=(q[s+1]in'-7J')or-(q[s-1]in'-LF');v=h==0
while'S'!=t:P+=[[x,y]];x+=h;y+=v;t=G[y][x];h+=(t in'LF')-(t in'J7');v+=(t in'F7')-(t in'JL')
print(len(P)//2,sum(sum((y==t)*(x<s)and G[y][x]in'|JLS'for x,y in P)%(2-([s,t]in P))for t in R for s in R))

could be a byte smaller if not timeout

winter prawn
#

just woke up. i don't think i even understand the question today

limpid stag
winter prawn
# limpid stag part 1 or part 2?

nvm, solved it with something similar to flood fill. was talking about p2.
also, your golf doesn't work for my p2. runs quite easily on my system in about 7s but answer is off by 2%

limpid stag
limpid stag
#

it might rely on the shape of the S in the input

winter prawn
limpid stag
#

hmmmm

#

not sure what else is wrong then

#

But I think it's in that check

#

can you dm me your input?

winter prawn
limpid stag
#

yeah just saw it as i sent it oops

cerulean lantern
#

Feel free to go compare the code with the ato docs lol I don't really know how to use websockets

limpid stag
#

[Day 10] 351

*G,=open(0)
R=range(140)
for t in R:
 q=G[t]
 for s in R:
  if'S'==q[s]:x,y,*P=s,t;h=(q[s+1]in'-7J')or-(q[s-1]in'-LF');v=h==0
while'S'!=t:P+=[[x,y]];x+=h;y+=v;t=G[y][x];h+=(t in'LF')-(t in'J7');v+=(t in'F7')-(t in'JL')
print(len(P)//2,sum(sum(G[b][a]in'||FJ7LSS'[G[y-1][x]in"|F7"::2]for a,b in P if b==t and a<s)%(2-([s,t]in P))for t in R for s in R))

@winter prawn

cerulean lantern
#

I think you can save 2B by changing the brackets for separated expressions

h+=(a)-(b);v+=(c)-(d)
h+=a;h-=b;v+=c;v-=d
limpid stag
#

you are correct

#

349

*G,=open(0)
R=range(140)
for t in R:
 q=G[t]
 for s in R:
  if'S'==q[s]:x,y,*P=s,t;h=(q[s+1]in'-7J')or-(q[s-1]in'-LF');v=h==0
while'S'!=t:P+=[[x,y]];x+=h;y+=v;t=G[y][x];h+=t in'LF';h-=t in'J7';v+=t in'F7';v-=t in'JL'
print(len(P)//2,sum(sum(G[b][a]in'||FJ7LSS'[G[y-1][x]in"|F7"::2]for a,b in P if b==t and a<s)%(2-([s,t]in P))for t in R for s in R))
#

theres probably a better way of finding the start, the first double for loop does only that

#

[Day 10] 338

*G,=open(0)
R=range(140)
for t in R:
 for s in R:
  if'S'==G[t][s]:x,y,*P=s,t;v=-(q:=G[t-1][s]in'|F7')or(G[t+1][s]in'|JL');h=v==0
while'S'!=t:P+=[[x,y]];x+=h;y+=v;t=G[y][x];h+=t in'LF';h-=t in'J7';v+=t in'F7';v-=t in'JL'
print(len(P)//2,sum(sum(G[b][a]in'||FJ7LSS'[q::2]for a,b in P if b==t and a<s)%(2-([s,t]in P))for t in R for s in R))
winter prawn
#

[Day 10] 314

*G,=open(0)
R=range(140)
for t in R:
 q=G[t]
 for s in R:
  if'S'==q[s]:x,y,*P=s,t;h=0;v=1
while'S'!=t:P+=[[x,y]];x+=h;y+=v;t=G[y][x];h+=t in'LF';h-=t in'J7';v+=t in'F7';v-=t in'JL'
print(len(P)//2,sum(sum(G[b][a]in'||FJ7LSS'[G[y-1][x]in"|F7"::2]for a,b in P if b==t and a<s)%(2-([s,t]in P))for t in R for s in R))```
this works for me. combine your save with it if it works
limpid stag
#

doesnt h=0 v=1 rely on input shape

#

gives error for me

winter prawn
limpid stag
#

index out of range

winter prawn
limpid stag
#

because it is a different S shape for start

#

its also why old version worked for me and not you

limpid stag
winter prawn
limpid stag
#

if theres a pipe above, your start dy is -1 because you go up, if theres a pipe below then dy becomes 1 so you go down

#

if its neither then just set it to 0 and dx to 1 because there has to be a pipe there

#

i used sense-making variable names like v for vertical and h for horizontal

#

but yeah today is a difficult one to test

#

[Day 10] 328

*G,=open(0)
R=range(140)
x,y,*P=max((G[t].find("S"),t)for t in R)
v=-(q:=G[y-1][x]in'|F7')or(G[y+1][x]in'|JL')
h=t=v==0
while'S'!=t:P+=[[x,y]];x+=h;y+=v;t=G[y][x];h+=t in'LF';h-=t in'J7';v+=t in'F7';v-=t in'JL'
print(len(P)//2,sum(sum(G[b][a]in'||FJ7LSS'[q::2]for a,b in P if b==t and a<s)%(2-([s,t]in P))for t in R for s in R))
#

finally a better way of finding the start

#

h needs to be 1 if v is -1 or 1

cerulean lantern
#

That doesn't look like it works

winter prawn
cerulean lantern
#

Oh yeah I need to go revert the broken solutions from earlier lol

limpid stag
#

yup

#

you can just revert

#

all of them

#

because im pretty sure i did it wrong since the first one

cerulean lantern
#

I've just fully reverted everything from today lol

#

(tessaract's input is still in validation because it isn't tracked)

limpid stag
cerulean lantern
#

Yeah I looked at the commit history before doing it

limpid stag
#

oh

#

[Day 10] 254

*G,=open(0)
x,y,*P=max((G[t].find("S"),t)for t in range(140))
v=G[y+1][x]in'|JL'or-(G[y-1][x]in'|F7')
h=t=v==0
while'S'!=t:P+=[(x,y)];x+=h;y+=v;t=G[y][x];h+=t in'LF';h-=t in'J7';v+=t in'F7';v-=t in'JL'
print(len(P)//2,4900-sum(34<y<105>x>34for x,y in P))
#

why tf does that work

#

[Day 10] 234

*G,=open(0)
x,y=max((G[t].find("S"),t)for t in range(140))
v=G[y+1][x]in'|JL'or-(G[y-1][x]in'|F7')
h=t=v==0
P=Q=0
while'S'!=t:P+=1;Q+=34<y<105>x>34;x+=h;y+=v;t=G[y][x];h+=t in'LF';h-=t in'J7';v+=t in'F7';v-=t in'JL'
print(P//2,4900-Q)
#

can save 2 more by adding .5 to P and not dividing but then the answer has .0

limpid stag
#

[Day 10] 223

*G,=open(0)
x,y=max((G[t].find("S"),t)for t in range(140))
v=G[y+1][x]in'|'or-(G[y-1][x]in'|')
h=t=v==0
P=Q=0
while'S'!=t:P+=1;Q+=34<y<105>x>34;x+=h;y+=v;h+='-|LF'.find(t:=G[y][x])//2;v+='-|F7'.find(t)//2
print(P//2,4900-Q)
limpid stag
#

[Day 10] 193

*G,=open(0)
D=U=C=K=0
x=y=-1
while x<0:y+=1;x=G[y].find("S")
v=G[y+1][x]>'{'or-1
while'S'!=D:U+=1;C+=x>34<y<105>x;x+=K;y+=v;K+='-|LF'.find(D:=G[y][x])//2;v+='-|F7'.find(D)//2
print(U//2,4900-C)
devout flax
#

๐Ÿฆ†

winter prawn
#

[Day 10] 190

*G,=open(0)
x=y=D=U=C=K=0
while x<1:y+=1;x=G[y].find("S")
v=G[y+1][x]>'{'or-1
while'S'!=D:U+=1;C+=x>34<y<105>x;x+=K;y+=v;K+='-|LF'.find(D:=G[y][x])//2;v+='-|F7'.find(D)//2
print(U//2,4900-C)```
limpid stag
#

[Day 10] 179

*G,=open(0,'rb')
x=y=D=U=C=K=0
while x<1:y+=1;x=G[y].find(83)
v=G[y+1][x]>99or-1
while 83!=D:U+=1;C+=x>34<y<105>x;x+=K;y+=v;K+=1-9*(D:=G[y][x])%14%3;v+=D%38%3-1
print(U//2,4900-C)
limpid stag
#

[Day 10] 166

G=open(0,'rb').read()
D=U=C=0;K=141
p=G.find(83)
v=(G[p+K]>99or-1)*K
while 83!=D:U+=1;C+=34<p//K<105>p%K>34;p+=v;v+=1-9*(D:=G[p])%14%3+(D%38%3-1)*K
print(U//2,4900-C)
winter prawn
#

[Day 10] 164

G=open(0,'rb').read()
D=U=C=0;K=141
p=G.find(83)
v=(G[p+K]>99or-1)*K
while 83!=D:U+=1;C+=34<p//K<105>p%K>34;p+=v;v+=1-9*(D:=G[p])%14%3+D%38%3*K-K
print(U//2,4900-C)```
winter prawn
#

[Day 10] 156

G=open(U:=0,'rb').read()
C=D=K=141
p=G.find(83)
v=G[p+K]//41-3^K
while 83^D:U+=1;C-=34<p//K<105>p%K>34;D=G[p:=p+v];v+=(3-D%68%11^2or K)^K
print(U//2,C+4759)```
limpid stag
river kestrel
#

[day 11] 280 base ```py
from itertools import*
A=C=0
R=range
*I,=open(0)
*J,=zip(I)
for (a,b),(c,d)in combinations([(i,j)for i in R(140)for j in R(140)if'#'==I[i][j]],2):m=len(e:=R(b,d,1|-(b>d)))+len(f:=R(a,c,1|-(a>c)));C+=sum('#' not in C[t]for R,C in[(e,J),(f,I)]for t in R);A+=m
print(A+C,A+999999
C)

#

[Day 11] 276 ```py
from itertools import*
A=C=0
R=range
*I,=open(0)
*J,=zip(I)
for (a,b),(c,d)in combinations([(i,j)for i in R(140)for j in R(140)if'#'==I[i][j]],2):A+=len(e:=R(b,d,1|-(b>d)))+len(f:=R(a,c,1|-(a>c)));C+=sum('#' not in C[t]for R,C in[(e,J),(f,I)]for t in R)
print(A+C,A+999999
C)

limpid stag
#

[day 11] 271

*I,=open(0)
R=range
for q in 2,10**6:
 G=[];D=0
 for i in R(len(I)):
  for j in R(len(I[i])):
   if I[i][j]=="#":
    for g in G:
     for x in R(*sorted([g[0],j])):D+=q**all(l[x]=='.'for l in I)
     for y in R(g[1],i):D+=q**(I[y].count("#")<1)
    G+=[(j,i)] 
 print(D)
cerulean lantern
#

Oh my

limpid stag
#

who needs itertools anyway

cerulean lantern
#

[Day 11] 270

*I,=open(0)
R=range
for q in 2,10**6:
 G=[];D=0
 for i in R(len(I)):
  for j in R(len(I[i])):
   if I[i][j]=="#":
    for g in G:
     for x in R(*sorted([g[0],j])):D+=q**all(l[x]>'#'for l in I)
     for y in R(g[1],i):D+=q**(I[y].count("#")<1)
    G+=[(j,i)] 
 print(D)
river kestrel
#

[Day 11] 253 ```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 g in G:
for x in R(*sorted([g[0],j])):D+=q
all(l[x]>'#'for l in I)
for y in R(g[1],i):D+=q
*-~-('#'in I[y])
G+=(j,i),
print(D)

cerulean lantern
#

[Day 11] 252

*I,=open(0)
R=range
for q in 2,10**6:
 *G,D=0,
 for i in R(140):
  for j in R(140):
   if'.'>I[i][j]:
    for g in G:
     for x in R(*sorted([g[0],j])):D+=q**all(l[x]>'#'for l in I)
     for y in R(g[1],i):D+=q**-~-('#'in I[y])
    G+=(j,i),
 print(D)
limpid stag
#

[Day 11] 245

*I,=open(0)
R=range
for q in 2,10**6:
 *G,D=0
 for i in R(140):
  for j in R(140):
   if'.'>I[i][j]:
    for g in G:D+=sum(q**all(l[x]>'#'for l in I)for x in R(*sorted([g[0],j])))+sum(q**-~-('#'in I[y])for y in R(g[1],i))
    G+=(j,i),
 print(D)
river kestrel
#

there's supposed to be a comma at the end of *G,D=0

#

ovs then wakes up later and drops a sub-200

cerulean lantern
#

Lmao