#AoC 2022 | Code Golf Solutions & Spoilers
1 messages Β· Page 4 of 1
why does this take a few seconds
because we're floodfilling a lot of space
because we don't check bounds at all
We're filling from the origin
i'm gonna wait for 20s again and see if my changes worked
yeah gets the right answer for me
which they probably do so
[Day 18] untested 205 ```py
N=lambda x,y,z:{*zip([x-1,x+1]+[x]*4,[y,y,y-1,y+1,y,y],[z]*4+[z-1,z+1])}
S=lambda A:sum(len(N(*i)-A)for i in A)
C={*map(eval,open(0))}
F={(0,)*3}
exec('for c in{*F}:F|=N(*c)-C\n'*69)
print(S(C),S(F)-57966)
But if there was a block in the way
It wouldn't be able to reach 0,0,10 anymore
input is a sphere, you are not going to get that kind of point
confirmed
you would need an input that blocks in all 3 directions
Not necessarily
like i said, you will never get such an input
Just 1 block in the wrong location would affect the result
Idk if it actually happens in any input
But it can
because then it wouldn't be a sphere
yeah
if you just look at it from the x,y perspective
once you reach (22, 22) you're basically fine since all points <22
for it to not work it'd need to block all paths to (22,22)
which basically make it very close to a flat plane in that direction
nah enthusiast is right, the thing is, i'm also right because such an input won't exist
you get to all locations that can be flooded within 69, but if you have enough points blocking the way, then the corner at the very end will be affected
because it would take longer than 69 to get there
and that affects the constant we subtract
yeah but as you said it'd be more of a swiss cheese square and not a sphere
almost sub 200
Can we recude the constant by running the floodfill for shorter?
we probably can
How long does everyone's floodfill take
i'll try getting it to 4 digits
I think mine was 72
yeah 69 is like the minimum
How about 5 digits?
it's at 5 digits tho
running the golf takes 11.3s for me
takes like half a minute for me
Isn't it 118806?
hardware diff
that's for 99
for 69 it's 57966
I have a 6 year old mac
Ah ic
don't expect much from it
i have a 1/2 year old mac
yeah
so is 118806
they're only prime because we need to add 6 for the tips
does this take like 20s for you? Also, it's 69 for everyone? pog!
m2 v m1 π
i just wish for some python assignment trick or an efforted rewrite to make a sub-200
Also, were counting surface area and not volume
I'd bet on refactoring the neighbours bit
57966 is 6 * 9661, 57960 is 6 * a bunch of factors
I was thinking some eval*6 trick but idk where to start with that
same with 118806 vs 118800
wait i think i have an idea
just gonna wait for the 20 seconds or something that takes to run this
lmao
at least this was better than that golf which took 2 mins
[Day 18] 204 ```py
N=lambda x,y,z:{*zip([x-1,x+1]+[x]*4,[y,y,y-1,y+1,y,y],[z]*4+[z-1,z+1])}
S=lambda A:sum(len(N(*i)-A)for i in A)
C={*map(eval,open(0))}
F={(0,)*3}
exec('for c in{*F}:F|=N(*c)-C\n'*69)
print(S(C),S(F)%9661)
works for me. why did you strike it?
oh nice
oh very nice
i striked "untested"
i didn't strike the whole thing
lol
we should go back after Christmas and tally up the amount of unexpected 69s this year
didn't understand the logic of the numbers that were %
i think golfing breakthrough should be thoroughly focused on this line ```py
N=lambda x,y,z:{*zip([x-1,x+1]+[x]*4,[y,y,y-1,y+1,y,y],[z]*4+[z-1,z+1])}
or golf the programs such that a total of 69 69s show up. kek
it's too long
what about some matrix logic? maybe too long.idk
that were %
huh
57966 is 6*9661, so subtracting 57966 keeps residue the same mod 9661
we know the answer is gonna be probably less than 9661, so taking mod 9661 gives us the unique number with the same residue as the original that is less than 9661, which is gonna be the answer
57966 is just the offset from floodfilling 69 times unbounded
it's the surface area of the diamond thing after floodfilling 69 times
I'm gonna go to bed
and hope that in my dreams the python gods visit me with a shortened formula for the neighbours in 3d space
imagine Β± operator
true
I don't have python2 but this most likely would work in it
[Day 18] 201
N=lambda x,y,z:{*zip([x-1,x+1]+[x]*4,[y,y,y-1,y+1,y,y],[z]*4+[z-1,z+1])}
S=lambda A:sum(len(N(*i)-A)for i in A)
C={*map(eval,open(0))}
F={(0,)*3}
exec'\nfor c in{*F}:F|=N(*c)-C'*69
print S(C),S(F)%9661
i thought macos came with python2
i must've manually installed it at some point then
it defaults to python3.8. for me
must be
i think 204/201 is the limit
what if we use integers instead of tuples?
since we know it's bound between -1 and 22, we can just use base 24
this would make C much longer but would make N much shorter
wdym, those integers would need to be added to a collection like a tuple/list tho right?
we just convert each tuple to an integer
return (x + 1) + (y + 1) * 24 + (z + 1) * 24 * 24```
something like this?
of course can be golfed
this way we can directly add tuples together
i'm not sure if we'd need bounds for this though
this is basically a different integer for every neighbor of x,y,z or one for all 6 neighbors per x,y,z?
also, N would still have the N=lambda x,y,z:... which will add to the character. The net difference may be very less
@orchid charm any luck with the integer thingy? i'm still confused about what you were trying to explain
i was playing chess
do you need a challenge?
i just started code.golf and it's amazing!
shortest solution to fizzbuzz, I got. How did someone 58 byte/53 character it?
probably something to do with slicing FizzBuzz like this? ```py
print("FizzBuzz"[x%-3&4:12&8+x%-5]or x)
or python 2?
oh wow i actually recognize some people in their discord
from back when i played tons of clash of code
i was #1 in the us at one point
how to do this
?
fizzbuzz in 58
uh i'll try after dinner
[Day 18] 195 ```py
N=lambda x:{x-1,x+1,x-300,x+300,x-9e4,x+9e4}
S=lambda A:sum(len(N(i)-A)for i in A)
C={x+y300+z9e4 for x,y,z in map(eval,open(0))}
F={0}
exec('for c in{*F}:F|=N(c)-C\n'*69)
print(S(C),S(F)%9661)
it turns out you can use negative numbers in the base system as well
otherwise things like balanced ternary wouldn't exist
@urban torrent sub 200!
I don't think the constants can be made shorter
Another 195 which uses base 139 instead ```py
N=lambda x:{x-1,x+1,x-b,x+b,x-bb,x+bb}
S=lambda A:sum(len(N(i)-A)for i in A)
b=139
C={x+yb+zb*b for x,y,z in map(eval,open(0))}
F={0}
exec('for c in{*F}:F|=N(c)-C\n'*69)
print(S(C),S(F)%9661)
[Day 18] 193
N=lambda x:{x-1,x+1,x-b,x+b,x-b*b,x+b*b}
S=lambda A:sum(len(N(i)-A)for i in A)
b=9661
C={x+y*b+z*b*b for x,y,z in map(eval,open(0))}
F={0}
exec('for c in{*F}:F|=N(c)-C\n'*69)
print(S(C),S(F)%b)```
[Day 18] 192
N=lambda x:{x-1,x+1,x-b,x+b,x-d,x+d}
S=lambda A:sum(len(N(i)-A)for i in A)
b=9661
F={d:=b*b}
C={x+y*b+z*d for x,y,z in map(eval,open(0))}
exec('for c in{*F}:F|=N(c)-C\n'*69)
print(S(C),S(F)%b)
using d doesn't save any characters btw
i just happened to be testing it
b:=9661 in there works as well
That is still 59.
Noice!
Haven't had the time to see it. I will in a few hours
can you explain the math behind this?looks interesting
base 139?
like binary, ternary, etc.
instead of storing x,y,z tuples you store x + y*base + z*base**2
and overflow/underflow doesn't happen if the base is big enough
[Day 18] 191 but Code should just take a few months to run I guess
N=lambda x:{x-1,x+1,x-b,x+b,x-d,x+d}
S=lambda A:sum(len(N(i)-A)for i in A)
b=9661
F={d:=b*b}
C={x+y*b+z*d for x,y,z in map(eval,open(0))}
exec('for c in{*F}:F|=N(c)-C\n'*b)
print(S(C),S(F)%b)
ohh sadge. I thought it was just hella slow
it literally seems impossible to me rn. Threw everything I had at it π
What's your best? Mine is 61
anyone golfed today?
nope
Got from reddit
That is to expand the search area
stuck with fibonacci on 38 as well when best is 36 π
Blueprint 28: Each ore robot costs 4 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 7 clay. Each geode robot costs 2 ore and 7 obsidian.
doesn't seem to work.
should give 13 but returns 12 instead. rest all are correct
i have 36 best
anyone who was at #esoteric-python at a certain time probably had 36 best
I dm'ed you the best I got.
How can you POSSIBLY shave more chars?
do we just not have a day 19 golf
i finally did it because i was finished with exams
I mean given that my code apparently doesn't even work for every input I'm not sure how doable that is
π
Day 19 seems to be a fairly ridiculous problem lol
i used z3, soβ¦
Lmao nice
can't golf mine either
yeah, most of the solutions on reddit aren't guaranteed for all inputs
rip
who's starting with day 20 golf
I'm working on golfing mine
[Day 20] base golf, 250 ```py
A=[int(s)for s in open(0)]
m=0
I,=L=range(f:=5000)
S="i=0\nwhile i<f:x=I.index(i);del I[x];I.insert((x+A[i])%(f-1),i);i+=1\n"
G="for x in 1,2,3:m+=A[I[(I.index(A.index(0))+x1000)%f]]\nprint(m);"
exec(S+G+"A=[x*811589153 for x in A];I,=L\n"+S10+G)
[Day 20] 232
A=[*map(int,open(m:=0))]
*I,=L=range(f:=5000)
S="for i in L:del I[x:=I.index(i)];I.insert((x+A[i])%~-f,i)\n"
G=S+"for x in 1,2,3:m+=A[I[(I.index(A.index(0))+x*1000)%f]]\nprint(m);"
exec(G+"A=[x*811589153 for x in A];*I,=L\n"+S*9+G)
[Day 20] 229 ```py
A=[map(int,open(m:=0))]
I,=L=range(f:=5000)
G="for i in L:del I[x:=I.index(i)];I.insert((x+A[i])%~-f,i)\nfor x in 1,2,3:m+=A[I[(I.index(A.index(0))+x1000)%f]]\nprint(m);"
exec(G+"A=[x811589153 for x in A];*I,=L\n"+G[:57]*9+G)
[Day 20] 227 ```py
A,=map(int,open(m:=0))
I,=L=range(f:=5000)
G="for i in L:del I[x:=I.index(i)];I.insert((x+A[i])%~-f,i)\nfor x in 1,2,3:m+=A[I[(I.index(A.index(0))+x1000)%f]]\nprint(m);"
exec(G+"A=[x811589153for x in A];*I,=L\n"+G[:57]*9+G)
oh wait
p2 doesn't work for me
off by part 1
lmao
what's weird is that also happened the first time i removed the space between 811589153 and for
β«now it works for some reason (for me)
idrk
oh wait i didn't check my p2
[Day 20] 231 this seems to work ```py
A,=map(int,open(m:=0))
I,=L=range(f:=5000)
G="for i in L:del I[x:=I.index(i)];I.insert((x+A[i])%~-f,i)\nfor x in 1,2,3:m+=A[I[(I.index(A.index(0))+x1000)%f]]\nprint(m);"
exec(G+"A=[x811589153for x in A];*I,=L;m=0\n"+G[:57]*9+G)
[Day 20] 228 with the space ```py
A,=map(int,open(m:=0))
I,=L=range(f:=5000)
G="for i in L:del I[x:=I.index(i)];I.insert((x+A[i])%~-f,i)\nfor x in 1,2,3:m+=A[I[(I.index(A.index(0))+x1000)%f]]\nprint(m);"
exec(G+"A=[x811589153 for x in A];*I,=L\n"+G[:57]*9+G)
does this work?
ye
yes
also this is 231
wait
fixed
ok
works for me for some reason
^
Im making the 228 again
[Day 20] 228
*A,=map(int,open(m:=0))
*I,=L=range(f:=5000)
G="for i in L:del I[x:=I.index(i)];I.insert((x+A[i])%~-f,i)\nfor x in 1,2,3:m+=A[I[(I.index(A.index(0))+x*1000)%f]]\nprint(m);A=[x*811589153for x in A];*I,=L;m=0\n"
exec(G+G[:57]*9+G)```
sorry idr who did it
I did
so i'm just gonna repost it
smh
oh
why does the 227 work for me
because the 228 also works for you
it does?
β«and that was based on the 229
it doesn't work for me
the base golf doesn't work
base golf doesn't even reset m
which is why it doesnt work
why does it always have to be cereal lmao
[Day 20] 225
*A,=map(int,open(0))
*I,=L=range(f:=5000)
G="m=0\nfor i in L:del I[x:=I.index(i)];I.insert((x+A[i])%~-f,i)\nfor x in 1,2,3:m+=A[I[(I.index(A.index(0))+x*1000)%f]]\nprint(m);A=[x*811589153for x in A];*I,=L;"
exec(G+G[:61]*9+G)```
[Day 20] 221 ```py
A,=map(int,open(0))
I,=L=range(f:=5000)
G="\nfor i in L:del I[x:=I.index(i)];I.insert((x+A[i])%~-f,i)\nprint(sum(A[I[(I.index(A.index(0))+x1000)%f]]for x in(1,2,3)));A=[x811589153for x in A];*I,=L;"
exec(G+G[:57]*9+G)
[Day 20] 220
*A,=map(int,open(0))
*I,=L=range(f:=5000)
G="for i in L:del I[x:=I.index(i)];I.insert((x+A[i])%~-f,i)\nprint(sum(A[I[(I.index(A.index(0))+x*1000)%f]]for x in(1,2,3)));A=[x*811589153for x in A];*I,=L\n"
exec(G+G[:57]*9+G)```
smh how did I miss that

off by part 1 for me
wait wtf
231 doesn't even work
the 227 does
above is 231 and below is 227 ```py
py test_a.py < aocday20.txt
<string>:3: SyntaxWarning: invalid decimal literal
5498
3390007892081
py test_b.py < aocday20.txt
<string>:3: SyntaxWarning: invalid decimal literal
5498
3390007897579
@orchid charm try fixing part 1 of this
pretty simple, just don't prune
but that makes it take forever
it might take longer than an hour
how will not pruning, fix p1?
β¦
it prunes out the best solution
so obviously not pruning fixes this
you understand what the code does, right?
well whatever
i'll golf day 19 tomorrow
since i made a solution without z3
no, I haven't tried understanding it. I just changed the 2000 to a 5000 and p2 started working for me. Haven't tried anything else with that code atm
It was just quite short, so it would be golfable
well third party libs are no problem if the solution is short enough though
it works for me 
and so does this
G[:57]. Damnnn
what does the %f do?
oh nvm
it's modulo
f = lambda x:nums[idx[(idx.index(nums.index(0))+x)%len(idx)]]
I did this in my code. Would that shorten it? π€
nah, nvm, that's like 230 chars
if m is reset it gets off by p1
otherwise it's correct for me
Does the 221 work then?
why is it off by p1
yeah
do we have a day 19 golf yet?
ok i'm trying to golf my day 19 and i'm running out of variable names
i'm making a variable dictionary
i can't anymore
Just use this. This will work if there's no pruning. Just uses numpy if you're okay with that
#1050425859225436241 message
[Day 20] 202
*D,=open(0)
for k in 1,811589153:N=[k*int(x)for x in D];I=[*range(L:=len(N))];X=I.index;[I.insert((N[I.pop(j:=X(i))]+j)%~-L,i)for i in I*(k%71)];print(sum(N[I[(X(N.index(0))+p*1000)%L]]for p in[1,2,3]))
[Day 20] 200 ```py
D,=open(0)
for k in 1,811589153:N=[kint(x)for x in D];I=[range(L:=5000)];X=I.index;[I.insert((N[I.pop(j:=X(i))]+j)%~-L,i)for i in I(k%71)];print(sum(N[I[(X(N.index(0))+p*1000)%L]]for p in[1,2,3]))
[Day 20] 196 ```py
N=[int(x)for x in open(0)]
for k in 1,811589153:I=[range(L:=5000)];X=I.index;[I.insert((N[I.pop(j:=X(i))]k+j)%~-L,i)for i in I(k%71)];print(sum(kN[I[(X(N.index(0))+p*1000)%L]]for p in[1,2,3]))
[Day 20] 190 ```py
N,=map(int,open(0))
for k in 1,811589153:I=[range(L:=5000)];X=I.index;[I.insert((N[I.pop(j:=X(i))]k+j)%~-L,i)for i in I(k%71)];print(sum(kN[I[(X(N.index(0))+p1000)%L]]for p in[1,2,3]))
good news: i have a golf for day 19 that works for the most part
bad news: it's off by one for part 1 blueprint 1 and works fine for everything else
nvm figured it out
floating point error
[Day 19] 554 (without numpy)
import re,math as p
I=lambda *x:1+M(*map(p.ceil,x),0)
q=n=0
Z=0,0
e=1
M=max
for _,A,B,C,D,E,F in (map(int,re.findall('\d+',l))for l in open(0).read().split('\n')):
def d(r,l,s,g,b,c,o,t):
global m
m=M(m,g)
if(t-1)*t/2+g<m or t<1:return
for v,w,x,y,z,h,j,k in((o<M(A,B,C,E)and I((A-r)/o),A,*Z*2,0,1),(D>c and I((B-r)/o),B,*Z*2,1,0),(c*(F>b)and I((C-r)/o,(D-l)/c),C,D,*Z,1,*Z),(b and I((E-r)/o,(F-s)/b),E,0,F,1,*Z,0)):
if v:d(r+o*v-w,l+c*v-x,s+b*v-y,g+z*(t-v),b+h,c+j,o+k,t-v)
m=0;d(*Z*3,1,24);q+=_*m
if n<3:n+=1;d(*Z*3,1,32);e*=m
print(q,e)
can't wait for someone to tell me that it doesn't work on their input
here's the variable dict
var_dict = {
'q':'quality',
'n': 'counter for pt2',
'e': 'pt2 geode product',
'm': 'max geode',
'Z': (0,0),
'_': 'blueprint id',
'A': 'orebot ore cost',
'B': 'claybot ore cost',
'C': 'obsidianbot ore cost',
'D': 'obsidianbot clay cost',
'E': 'geodebot ore cost',
'F': 'geodebot obsidian cost',
'r': 'ore amount',
'l': 'clay amount',
's': 'obsidian amount',
'g': 'geode amount',
'b': 'obsidianbot count',
'c': 'claybot count',
'o': 'orebot count',
't': 'time left',
'v': 'condition/dt variable',
'w': 'ore change',
'x': 'clay change',
'y': 'obsidian change',
'z': 'geode change',
'h': 'orebot change',
'j': 'claybot change',
'k': 'obsidianbot change'
}
[Day 19] 538
import re,math as p
I=lambda *x:1+M(*map(p.ceil,x),0)
q=n=0
Z=0,0
e=1
M=max
for _,A,B,C,D,E,F in(map(int,re.findall('\d+',l))for l in open(0).read().split('\n')):
def d(r,l,s,g,b,c,o,t):
global m;m=M(m,g)
if(t-1)*t/2+g>m and t>1:[d(r+o*v-w,l+c*v-x,s+b*v-y,g+z*(t-v),b+h,c+j,o+k,t-v)for v,w,x,y,z,h,j,k in((o<M(A,B,C,E)and I((A-r)/o),A,*Z*2,0,1),(D>c and I((B-r)/o),B,*Z*2,1,0),(c*(F>b)and I((C-r)/o,(D-l)/c),C,D,*Z,1,*Z),(b and I((E-r)/o,(F-s)/b),E,0,F,1,*Z,0))if v]
m=0;d(*Z*3,1,24);q+=_*m
if n<3:n+=1;d(*Z*3,1,32);e*=m
print(q,e)
that's all i'm gonna do until someone confirms that this actually works
Having dinner. Will check in a bit
works for me
how fast is it?
within a few seconds
because i did just basically convert my solution
like 3 seconds
so we could probably shave a few optimizations
def part_b_solver(blueprints: list):
geodes = 1
for _, oo, co, obo, obc, go, gob in blueprints[:1]:
max_ore = max(oo, co, obo, go)
current_max = 0
def dfs(ore, clay, obs, geode, orebot, claybot, obsbot, time):
nonlocal current_max
if time <= 0:
current_max = max(current_max, geode)
return
elif geode + time*(time-1)//2 <= current_max:
return
# Build robots
if max_ore > orebot:
dt = max(ceil((oo-ore)/orebot), 0) + 1
dfs(ore + orebot * dt - oo, clay + claybot * dt, obs + obsbot * dt, geode,
orebot + 1, claybot, obsbot,
time - dt)
if obc > claybot:
dt = max(ceil((co-ore)/orebot), 0) + 1
dfs(ore + orebot * dt - co, clay + claybot * dt, obs + obsbot * dt, geode,
orebot, claybot + 1, obsbot,
time - dt)
if gob > obsbot and claybot:
dt = max(ceil((obo-ore)/orebot), ceil((obc-clay)/claybot), 0) + 1
dfs(ore + orebot * dt - obo, clay + claybot * dt - obc, obs + obsbot * dt, geode,
orebot, claybot, obsbot + 1,
time - dt)
if obsbot:
dt = max(ceil((go-ore)/orebot), ceil((gob-obs)/obsbot), 0) + 1
if dt < time:
dfs(ore + orebot * dt - go, clay + claybot * dt, obs + obsbot * dt - gob, geode + (time - dt),
orebot, claybot, obsbot,
time - dt)
dfs(0, 0, 0, 0, 1, 0, 0, 32)
geodes *= current_max
return geodes
it's based off this
orebot and obsbot got switched because it allows *Z*3
refer to variable dict for variables
wait lmao
all this time and effort
and Z3 is still here
[Day 19] 536
import re,math as p
I=lambda *x:1+max(*map(p.ceil,x),0)
q=n=0
Z=0,0
e=1
for _,A,B,C,D,E,F in(map(int,re.findall('\d+',l))for l in open(0).read().split('\n')):
def d(r,l,s,g,b,c,o,t):
global m;m=max(m,g)
if~-t*t/2+g>m and t>1:[d(r+o*v-w,l+c*v-x,s+b*v-y,g+z*(t-v),b+h,c+j,o+k,t-v)for v,w,x,y,z,h,j,k in((o<max(A,B,C,E)and I((A-r)/o),A,*Z*2,0,1),(D>c and I((B-r)/o),B,*Z*2,1,0),(c*(F>b)and I((C-r)/o,(D-l)/c),C,D,*Z,1,*Z),(b and I((E-r)/o,(F-s)/b),E,0,F,1,*Z,0))if v]
m=0;d(*Z*3,1,24);q+=_*m
if n<3:n+=1;d(*Z*3,1,32);e*=m
print(q,e)```
for future reference btw if you do A/o-r/o instead of (A-r)/o it doesn't work
probably because floating point or something idk
[Day 20] 188
*N,=map(int,open(0))
for k in 1,811589153:I=[*range(L:=5000)];X=I.index;[I.insert((N[I.pop(j:=X(i))]*k+j)%~-L,i)for i in k%71*I];print(sum(k*N[I[(X(N.index(0))+p*1000)%L]]for p in[1,2,3]))```
[Day 20] 187 ```py
N,=map(int,open(0))
for k in 1,811589153:I,=range(L:=5000);X=I.index;[I.insert((N[I.pop(j:=X(i))]k+j)%~-L,i)for i in k%71I];print(sum(kN[I[(X(N.index(0))+p1000)%L]]for p in[1,2,3]))
relooked at day 20 and it seems like everything's all correct

it took 17 hours to find that out
[Day 16] 476 ```py
import re,itertools as i
C="for x,b,f,o in*p,:\n A,B=m[x]\n for t in[(u,b,f)for u in A]+(~b&B and[(x,b|B,f+m[B])]or[]):\n if z.get(t,-1)<o+f:z[t]=o+f;p+=(t,o+f),\n"
z,m,p={},{},('AA',0,0,0)
for l in open(0):
a,b,c=re.findall('\d+|[A-Z]{2}',l);m[a]=c,0
if b:=int(b):m[d:=1<<len(m)]=b;m[a]=c,d
exec(C26)
r=[(k,max(x[1]for x in g))for k,g in i.groupby(sorted((k[1],z[k])for k in z),lambda x:x[0])]
exec(C4)
print(max(z.values()),max(b+d(a&c<1)for a,b in r for c,d in r))
I feel bad for whoever has to gather up all the golfs and put them in the github
we're 9 days behind
uh oops
that was supposed to be me and tessa
i had exams, will probably do it tomorrow
i'm 5 days into christmas break
I'm a month into Christmas break
we didn't get github perms tho
afaik
unless u got it as well
actually idk if tessa has exams tbf
my christmas break starts in 2 days
would be so much easier if discord had exact text matching or regex search
as well as search within forum posts
we do have the [Day x] thing to search for
just do like in: #1047673173447020564 [Day 12] or something
yeah but discord search sucks so much
we need to make lancebot keep track of the golfs
and have them accessible through a command
golfhelper for next year?
yeah maybe
if yall are still here next year
yeah I probably will
same
really depends on how school is
if i forget how to manage my time, probably won't be here next year
https://pypi.org/project/golfer-py/0.2.1/
This exists but it's in japanese. I went through a bit of their code and found out that they are using an ast to parse through the entire code to shorten/reduce it. We can build atop it perhaps?
nah I mean like a helper to assist with submitting golfs
not like an actual golf helper
[Day 21] base golf using @orchid charm's idea, 351 ```py
import re
L=eval
I=int
e=dict(re.findall("(.+): (.+)",open(0).read()))
D='g(%r)'
g=lambda d:L(A+B+D+C+D+E)
A,B,C,E='(len(h:=e[d].split())<2 and I(*h)','or L("','%s','"%(*h,)))'
t=I(g(s:='root'))
A,C,E='d=="humn"and"1j"or'+A[:-5]+'h[0]','+%r+',"+')'"+E
B+="'('+"
a,_,b=e[s].split()
a,b=L(g(a)),L(g(b))
if a.imag==0:a,b=b,a
print(t,I((b-a.real)/a.imag))
[Day 21] 264 with rewrite ```py
D=[]
for i in open(0):
a,b=i.split(':')
if'humn'==a:H=int(b)
else:
if'root'==a:R,S=i.split()[1::2]
D+=a+'='+b,
humn=1j
root=0
while root==0:
for i in D:
try:exec(i)
except:0
r=eval(R+'-'+S)
print(f"{root.real+root.imag*H:.0f} {abs(r.real/r.imag):.0f}")
[Day 21] 263 ```py
D=[]
for i in open(0):a,b=i.split(':');a=='humn'and(H:=int(b))or(D:=D+[a+'='+b]);a=='root'and(R:=b[:5])and(S:=b[7:])
humn=1j
root=0
while root==0:
for i in D:
try:exec(i)
except:0
r=eval(R+'-'+S)
print(f"{root.real+root.imag*H:.0f} {abs(r.real/r.imag):.0f}")
[Day 21] 259 ```py
D=[]
for i in open(0):
a,b=i.split(':');D+=a+'='+(a=='humn'and(H:=int(b))and'1j'or b),
if'root'==a:R,S=i.split()[1::2]
root=0
while root==0:
for i in D:
try:exec(i)
except:0
r=eval(R+'-'+S)
print(f"{root.real+root.imag*H:.0f} {abs(r.real/r.imag):.0f}")
[Day 21] 258 ```py
D=[]
for i in open(root:=0):
a,b=i.split(':');D+=a+'='+(a=='humn'and(H:=int(b))and'1j'or b),
if'root'==a:R,S=i.split()[1::2]
while root==0:
for i in D:
try:exec(i)
except:0
r=eval(R+'-'+S)
print(f"{root.real+root.imag*H:.0f} {abs(r.real/r.imag):.0f}")
[Day 21] 256 ```py
D=[]
for i in open(root:=0):
z=i.split;a,b=z(':');D+=a+'='+(a=='humn'and(H:=int(b))and'1j'or b),
if'root'==a:R,S=z()[1::2]
while root==0:
for i in D:
try:exec(i)
except:0
r=eval(R+'-'+S)
print(f"{root.real+root.imag*H:.0f} {abs(r.real/r.imag):.0f}")
how are real+imag and real/imag even get to the result?
no clue
#1054990914147340288 message this ig
and why is root root and not any var. Is it cz of some exec eval shenanigans?
yes
i've tried changing it to some shorter variable before
[Day 21] 252 Does this work for everyone? please check
D=[]
for i in open(root:=0):
z=i.split;a,b=z(':');D+=a+'='+(a=='humn'and(H:=int(b))and'1j'or b),
if'root'==a:R,S=z()[1::2]
while root==0:
for i in D:
try:exec(i)
except:0
r=eval(R+'-'+S)
print(f"{root.real+root.imag*H:.0f} {-r.real/r.imag:.0f}")
Invalid syntax
use a different python version?
I haven't even changed that part. I changed the last line
3.10.8
Doesn't work in 3.10.2 either
does this work for you?
#1050425859225436241 message
if not, the problem has propagated below
[Day 21] 247
D=[]
for i in open(root:=0):
z=i.split;a,b=z(':');D+=a+'='+(a=='humn'and(H:=int(b))and'1j'or b),
if'root'==a:R,S=z()[1::2]
while root==0:
for i in D:
try:exec(i)
except:0
r=eval(R+'-'+S)
print(int(root.real+root.imag*H),int(-r.real/r.imag))
[Day 21] 218
import re
exec(t:=re.sub("\(\):","=lambda:",re.sub("([a-z]+)",r"\1()",open(0).read())))
print(int(root()))
exec(re.sub('[-+*/]','-',re.findall("root.*",t)[0]))
exec("humn=lambda:1j")
x=root()
print(int(-x.real/x.imag))```
wtf
218 boisss wth
works for me. That too 64 ms
apparently doesn't work for specific inputs π
[Day 21] 220
import re
exec(t:=re.sub("\(\):","=lambda:",re.sub("([a-z]+)",r"\1()",open(0).read())))
print(int(root()))
exec(re.sub('[-+*/]','-',re.findall("root.*",t)[0]))
exec("humn=lambda:1j")
x=root()
print(round(-x.real/x.imag))
It's an FPE LMAO
what's FPE
Floating-point error
floating point error
lol ok
220 works though
are we allowing floating solutions? or should they be int-ed
[Day 21] 218
import re
G=print;H=exec
H(t:=re.sub("\(\):","=lambda:",re.sub("([a-z]+)",r"\1()",open(0).read())))
G(int(root()))
H(re.sub('[-+*/]','-',re.findall("root.*",t)[0]))
H("humn=lambda:1j")
x=root()
G(round(-x.real/x.imag))
218, use round
wait, they can be rounded up as well? else 216 will not work
(same problem as previous 218 -> 220)
ah done
The reason the previous one didn't work (and the same reason yours didn't) is because the real / imag calculation can be just below the right answer instead of just above it
[Day 21] 217 ```py
import re
G=print;H=exec
H(t:=re.sub("():",A:="=lambda:",re.sub("([a-z]+)",r"\1()",open(0).read())))
G(int(root()))
H(re.sub('[-+/]','-',re.findall("root.",t)[0]))
H("humn%s1j"%A)
x=root()
G(round(-x.real/x.imag))
was doing that LMAO
(if the 0000000000003 bit wasn't there, int would work)
I still don't understand how the real/imag thingy works though.
seems like magic to me'
It calculates a complex answer a - bi where a / b is the correct answer
ohh..i think I get it. damnnn
and why is root root?
and how is root() even working?
a friend did 206 but he is just joining the server now
It appears to be transpiling the input into a set of lambdas
Then running the one for root
[Day 21] 215 ```py
import re
G=print;H=exec
H(t:=re.sub("():",A:="=lambda:",re.sub("([a-z]+)",r"\1()",open(0).read())))
G(int(root()))
H(re.sub('[-+*/]','-',re.findall("root.",t)))
H("humn%s1j"%A)
x=root()
G(round(-x.real/x.imag))
[Day 21] 206
import re
exec(t:=re.sub("..:","=lambda:",re.sub("([a-z]+)","\\1()",open(0).read())))
S=root()
exec(re.sub(r'(root=.*) . (.*)',r'\1 - \2',t))
humn=lambda:1j
z=root()
print(f"{S:.0f}\n{-z.real/z.imag:.0f}")
nice
I tried to replace root with R, but no gain π¦
Hi, welcome
Welcome, I used to perl golf in good old times, I still claim that perl is much better for golfing π
(please use the format though)
the regexes are insane
how does minus work
[Day 21] hehe 203 ```py
import re
exec(t:=re.sub("..:","=lambda:",re.sub("([a-z]+)","\1()",open(0).read())))
S=root()
exec(re.sub(r'(root=.) . (.)',r'\1-\2',t))
humn=lambda:1j
z=root()
print(f"{S:.0f}\n{-z.real/z.imag:.0f}")
It's comparing a and b
a == b -> a - b == 0
[Day 21] 199 Sub 200!
import re
exec(t:=re.sub("..:","=lambda:",re.sub("([a-z]+)","\\1()",open(0).read())))
S=root()
exec(re.sub(r'(root=.*) . (.*)',r'\1-\2',t))
humn=lambda:1j
z=root()
print(int(S),round(-z.real/z.imag))
Is using py2-style formatting shorter here? I feel like it might be
Or that
would you still need round-ing? or does inting work?
.0f does the rounding
ah
Isn't the newline required between p1 and p2? Here's just space
no need until you get the answer
as long as it displays the correct input it works in here
Any whitespace is considered valid
starwort's repo does that rule though ^
[Day 21] 193
import re
a=re.sub
exec(t:=a("..:","=lambda:",a("([a-z]+)","\\1()",open(0).read())))
S=root()
exec(a(r'(root=.*) . (.*)',r'\1-\2',t))
humn=lambda:1j
z=root()
print(int(S),round(-z.real/z.imag))
beat me to it, ahah
[Day 21] 192 ```py
import re
a=re.sub
exec(t:=a("..:","=lambda:",a("(\w{4})","\1()",open(0).read())))
S=root()
exec(a(r'(root=.) . (.)',r'\1-\2',t))
humn=lambda:1j
z=root()
print(int(S),round(-z.real/z.imag))
Well that's disappointing
what's your input
different 192, but skipping the int() and assuming that only root starts with ro
because it better not have numbers in the thousands
do you want the file?
I thought about it but considered it cheating. Or - gambling π
works for my input π
ok
so does print(31017034894002, 3555057453229) for mine π
kekw
@scarlet grove raw is not required for the first string on line 4
doesn't work for me though π
OK, it was nice to meet you, I have to leave for now, I'll drop later to see your sub 100 π
lol
Lmao
i have 831 as humn
[Day 21] 192 ```py
import re
a=re.sub
exec(t:=a("..:","=lambda:",a("([a-z]+)","\1()",open(0).read())))
S=root()
exec(a('(root=.) . (.)',r'\1-\2',t))
humn=lambda:1j
z=root()
print(int(S),round(-z.real/z.imag))
2116 here
ok why do i have to be different
Lmao
189 works for my input, but that's because my humn is 28
exec(t:=re.sub("..:","=lambda:",re.sub("(\w{4})","\\1()",open(0).read())))
S=root()
exec(re.sub('(ro.*). (.*)',r'\1-\2',t))
humn=lambda:1j
z=root()
print(S,round(-z.real/z.imag))```
[Day 21] 189 assuming no other vars start with ro but humn can be 1000+ ```py
import re
a=re.sub
exec(t:=a("..:","=lambda:",a("([a-z]+)","\1()",open(0).read())))
S=root()
exec(a('(ro.) . (.)',r'\1-\2',t))
humn=lambda:1j
z=root()
print(int(S),round(-z.real/z.imag))
so which one works for all inputs?
test the 190
This one I think
works for me
works
nice
real/imag is the slope of a complex number. wish there was a function for that π
what? i don't get it
real/imag is the multiplicative inverse of that
and you do kinda have a formula for that
tan(atan2(y,x))
or tan(arg(z))
but you would need to call, numpy or math for it
which will increase char length
if only you could just unpack real and imag values like a tuple
it's literally just y/x tbh
atan2 is just arctan with its range modified to fit convention
this, and numpy support for indexing 2d arrays with complex
and complex ints
it's using the fact that python will resolve dependencies between functions by itself.
so if you create a bunch of functions with proper names, it will know in what order to call them.
@urban torrent using @echo quartz code from another discord, it works, because this works: ```python
def f1():
return f2() + f3()
def f2():
return 1
def f3():
return 5
f1()
TBH, it's @steep swift 's code, which I only optimized
python uses dynamic scoping iirc
It's most about lazy resolving of object references - there's not much scope here, all is global.
β«so it's literally just loading the variable every time the variable is referenced
[Day 21] 180, same assumptions as above
import re
a=re.sub
exec(t:=a(":","=lambda:",a("( [a-z]+)","\\1()",open(0).read())))
S=root()
exec(a('(ro.+). ',r'R=\1-',t))
humn=lambda:1j
z=R()
print(int(S),round(-z.real/z.imag))
[Day 21] this is like the most ridiculous shortening ever but it works, 178 ```py
import re
a=re.sub
exec(t:=a(":","=lambda:",a("( [a-z]+)","\1()",open(0).read())))
S=root()
exec(a('(ro.+). ',r'R=\1-',t))
humn=lambda:1j
print(int(S),round(-R().real/R().imag))
this doesn't even make sense anymore. How did you even figure it out?
remind me what \2 was?
i literally just removed z=R() and its two references and replaced them with R()
β«i'm currently working on a one-exec version
but how did you R the root?
When replacing operator to minus in root=v1 op v2 he takes a chance to also replace root with R - very clever
pkubiak's idea
why can't we assign S the same way then? 
Yep, I just tried this but realized in the same point it changes operator to '-' so it would require two replacements, no gain.
holy moly
[Day 21] 176, same assumptions ```py
import re
a=re.sub
A='=lambda:'
t=a(":",A,a("( [a-z]+)","\1()",open(0).read()))+';'
exec(t+a('ro.+:(.+). ',r'S=root();humn%s1j;R=\1-'%A,t))
print(int(S),round(-R.real/R.imag))
no way i just made a breakthrough at night
night is the best time for golf
in fact it's the only time for golf
you do aoc during the day and golf at night
this channel is like a speakeasy but for golf
we got booted from the public and now we have to gather here in private
[Day 21] 174
idk what I changed but seems like this works. I'm on phone and this is 174 chars
import re
a=re.sub
A='=lambda:'
t=a(":",A,a("( [a-z]+)","\\1()",open(0).read()))+';'
exec(t+a('ro.+:(.+). ',r'S=root();humn%s1j;R=\1-'%A,t))
print(int(S),int(-R.real/R.imag))
wait
that means
[Day 21] 172 ```py
import re
a=re.sub
A='=lambda:'
t=a(":",A,a("( [a-z]+)","\1()",open(0).read()))+';'
exec(t+a('ro.+:(.+). ',r'humn%s1j;R=\1-'%A,t))
print(int(root()),round(-R.real/R.imag))
I'm pretty sure we don't need that t anymore, just cannot implement this
you changed round to int
ohh, i'm dumb, that won't work
he changed the wrong thing lmao
lmao
i thought he was the one that did root() but it turns out i had it partially done on my text editor
I have no idea what the golf is btw I'm still doing my day 21
would golf but hotel has shit internet
bruh
oh i found out why
the root() would've have updated value though, right?
β«no i mean technically updated return value but not updated code
β«humn updated code
this is crazy short
day 20 didn't even go that far
it's still 11 bytes away
it's shorter than day 3
you should put a space between the Day and 21 just for a consistent format to make it easier to search to put into the github
i don't think it is
the github says day 3 is 201
day 3 was 201
that's the github
is there a shorter golf floating around?
oh it isn't updated my bad
day 3 pins
shortest is 156
why doesn't this work again
does it fail on some inputs
@wraith crypt's input was rounding up
some FPE
ah
what original operator do you guys have for root?
if everyone has plus we can get rid of a character
also tessa
[Day 21] 175
import re
a=re.sub
t=a(':',A:='=lambda:',a('( [a-z]+)','\\1()',open(0).read()))+';'
exec(t+a('ro.+:(.+). ',fr'S=root();humn{A}1j;R=\1-',t))
print(int(S),round(-R.real/R.imag))
actually lemme just edit a few things to make it cleaner
changed the " to ' for consistency
shame no f string walruses
[Day 21] Tentative 174, assumes the original root operator is +, ping me if yours isn't
import re
a=re.sub
t=a(':',A:='=lambda:',a('( [a-z]+)','\\1()',open(0).read()))+';'
exec(t+a('ro.+:(.+) ',fr'S=root();humn{A}1j;R=\1-',t))
print(int(S),round(-R.real/R.imag))
So you're the one who got the idea of using complex numbers?
yeah
kudos
[Day 21] Tentative 170 (and actually yours doesn't work for me due to this extra semicolon)
import re
a=re.sub
t=a(':',A:='=lambda:',a('( [a-z]+)','\\1()',open(0).read()))
exec(t+a('ro.+:(.+) ',fr'S=root();humn{A}1j;R=\1-',t))
print(int(S),round(-R.real/R.imag))
the extra semicolon is from the trailing newline
extra semicolon?
i think, at least
t=...+';'
doesn't work for me
without the semicolon you need a trailing newline
$ python3 golf2 <input-d21.txt
Traceback (most recent call last):
File "/home/kompas/git/aoc/2022/golf2", line 4, in <module>
exec(t+a('ro.+:(.+) ',fr'S=root();humn{A}1j;R=\1-',t))
File "<string>", line 2284
;pmqg=lambda: 2
^
SyntaxError: invalid syntax
Traceback (most recent call last):
File "/Users/stickie/PycharmProjects/AdventOfCode2022/Tools/golf.py", line 4, in <module>
exec(t+a('ro.+:(.+) ',fr'S=root();humn{A}1j;R=\1-',t))
File "<string>", line 2621
rbzv=lambda: gzpt() - spng()sbdn=lambda: bctf() + msbv()
^^^^
SyntaxError: invalid syntax
y'all this is because of the trailing newline or lack thereof
Well, I'm getting input with wget - so the question is whos input.txt is wrong?
we usually do no trailing newline i think
yeah
apparently that's what aoc does
INPUT="input-d${DAY}.txt"
curl "https://adventofcode.com/$YEAR/day/$DAY/input" \
-o $INPUT \
-H 'authority: adventofcode.com' \
-H 'cache-control: max-age=0' \
-H "cookie: ${COOKIE}" \
--compressed
wasn't my decision
Is it curl adding missing newline at the end?
Are there any rules for the golf? I think that should be clarified
yeah, we have inputs without trailing newlines for golfing
even though the actual inputs do have trailing newlines (at least for me)
ok, a bit strange but ACK
we've had this issue before
just preaching to the choir lol
so since we're sticking to (int) space (int) format, are we ever gonna go back and fix that one day where the answer was given as (pt1)+(pt2)j
How about feature request to python to make complex iterables? π then we could just print(*z)
BTW, if the answer is 123 then is 123.0 correct? Would aoc accept it or not?
we've had to convert to ints in the past
honestly i should just write my gaussian integer class one day
i'd have so many uses for it
except it'd be slow af
But it wouldn't work for today, as we had non-integer divisions?
plus for what?
works for me
$ grep root: input-d21.txt
root: qntq + qgth
Yep, we discussed it - I have input.txt with final newline, as for some reason the rule is it shouldn't be there.
yeah, because the input given in AOC doesn't have it
orly?
...unless you mean some different "given in AOC"
(or maybe they fixed it lately - IDK)
Actually, any simple (linux) way to strip that last final newline so I can test my script according to the rules?
Yep, works, ty
if your root was originally like
root: abcd + wxyz
Well... Nobody even tries today's task?
What time zone are you? I'm pretty sick (literally) of getting up before 6am for last 3 weeks
same here. the question is lacking the fun element. It's just tedious and boring.
I recently discovered code.golf. Really fun website. Have been doing a few of their problems in the last few days.
had to travel today
so i couldn't
actually i'll be traveling for the next few days
up until end of advent
Strange. Looks like there's a life beyond AoC?
if no one else is doing a golf i can try to turn mine into one
tho it'd probably be huge and not a good golf
yeah even just my parsing is 347 characters lmao
re?
import re,itertools as i
p,r,e=i.pairwise,range,enumerate
S=re.findall('\d+|L|R',(f:=open(0).read().split('\n\n'))[0])
D=sorted((min(map(lambda z:(z.real,z.imag),d)),d)for n,x in p(r(0,201,50))for m,y in p(r(0,151,50))if(d:={i:v for i,v in((x+y*1j,v=='#')for x,r in e(f[1].split('\n'))for y,v in e(r)if v in'.#')if n<=i.real<x and m<=i.imag<y}))
that's literally just converting the stuff in my parser to golf
and it's already chonk
probably better to use a 3D solution i think
anyone have any idea how to extract a pattern from this for golf
(x,y) refer to complex numbers btw
i just had them written out in vector form for readability
[Day 23 part 2] works for example but not actual input ```py
e=enumerate
j=1j
N={x+y*j for y,l in e(open(0))for x,c in e(l)if'#'==c}
E={n:=0}
A=[-1-j,-j,1-j,1,1+j,j,j-1,-1,-1-j]
D=[A[2:5],A[:3],A[4:7],A[6:]]
while N^E:
E={*N};N=set();D=D[1:]+D[:1];P={}
for e in E:
if len(a:={i for i in A if e+i in E})and(l:=next((e+i[1]for i in D if not{*i}&a),0)):P[l]=*P.get(l,()),e
else:N|={e}
for l,e in P.items():N|=[{l},{*e}][len(e)-1]
if n==9:...#do part 1 here
n+=1
print(n)
ah yes
import numpy as np
from collections import defaultdict
data = open(0).read()
grid = np.array([[i == '#' for i in line] for line in data.splitlines()], bool)
new_elves = set(int(j) + 1j * int(i) for i, j in zip(*np.nonzero(grid)))
elves = set()
adj = {
'NW': -1 - 1j,
'N': - 1j,
'NE': + 1 - 1j,
'W': - 1,
'E': + 1,
'SW': + (-1 + 1j),
'S': + 1j,
'SE': + (1 + 1j)
}
propose = [
['E', {'NE', 'E', 'SE'}],
['N', {'NW', 'N', 'NE'}],
['S', {'SW', 'S', 'SE'}],
['W', {'NW', 'W', 'SW'}],
]
n = 0
while elves ^ new_elves:
elves = new_elves
propose.append(propose.pop(0))
proposals = defaultdict(set)
new_elves = set()
for elf in elves:
adjacent = frozenset(k for k, v in adj.items() if elf+v in elves)
if len(adjacent) == 0:
new_elves.add(elf)
continue
for k, v in propose:
if not (v & adjacent):
break
else:
new_elves.add(elf)
continue
proposals[elf + adj[k]].add(elf)
for loc, e in proposals.items():
if len(e) == 1:
new_elves.add(loc)
else:
new_elves |= e
n += 1
if n == 10:
min_real = float('inf')
max_real = 0
min_imag = float('inf')
max_imag = 0
for elf in new_elves:
r, i = int(elf.real), int(elf.imag)
min_real = min(min_real, r)
max_real = max(max_real, r)
min_imag = min(min_imag, i)
max_imag = max(max_imag, i)
print((max_imag - min_imag + 1) * (max_real - min_imag + 1) - len(elves))
print(n)
```original logic if anyone is interested
good ol' if n==9: ... #do part 1 here
great for golfing
reduces the character count drastically
I'll take a look later to see what the problem is
i'm still debugging my "golfed" day 22
but idk what makes it work for example but not actual
sitting at a nice and comfy 1572 characters
someone better come up with a better golf than this monstrosity
it's gonna be a stain on the github
lol
[Day 23 part 2] 393 ```py
e=enumerate
j=1j
N={x+y*j for y,l in e(open(0))for x,c in e(l)if'#'==c}
E={n:=0}
A=[-1-j,-j,1-j,1,1+j,j,j-1,-1,-1-j]
D=[A[2:5],A[:3],A[4:7],A[6:]]
while N^E:
E={*N};N=set();D=D[1:]+D[:1];P={}
for e in E:
if len(a:={i for i in A if e+i in E})and(l:=next((e+i[1]for i in D if not{*i}&a),''))!='':P[l]=*P.get(l,()),e
else:N|={e}
for l,e in P.items():N|=[{*e},{l}][len(e)==1]
n+=1
print(n)
so uh
[Day 22] 1212
import re,itertools as i
p,R,e,U=i.pairwise,range,enumerate,complex
J=1j
S=re.findall('\d+|L|R',(F:=open(0).read().split('\n\n'))[1])
*D,=map(lambda x:(U(*x[0]),x[1]),sorted((min(map(lambda z:(z.real,z.imag),d)),d)for n,x in p(R(0,201,50))for m,y in p(R(0,151,50))if(d:={i:v for i,v in((U(x,y),v=='.')for x,r in e(F[0].split('\n'))for y,v in e(r)if v in'.#')if n<=i.real<x and m<=i.imag<y})))
L=-1,J,1,-J
def g(a):
global S,D
s,w,f=*D[c:=0],J;o=s
for v in S:
if v in'LR':f*={'L':J,'R':-J}[v];continue
for _ in R(int(v)):
if(z:=s+f)not in w:C,F=a[c][f];O,W=D[C];r,i=(x:=s-o).real,x.imag;f,o,c,w,s=eval(['f,o,c,w,s','F,O,C,W,z'][W[z:=O+49*U(F==-1,F==-J)+(((1-2*(b:=(F.imag>F.real)^(f.imag>f.real)))*(i if f.real else r))+49*b)*{-1:J,J:1,1:J,-J:1}[F]]])
elif w[z]:s=z
return int(sum(x*y for x,y in zip((1000,4,1),(s.real+1,s.imag+1,{J:0,1:1,-J:2,-1:3}[f]))))
print(g([{i:(v,i)for i,v in zip(L,j)}for j in((4,1,2,1),(1,0,1,0),(0,2,4,2),(5,4,5,4),(2,3,0,3),(3,5,3,5))]),g([{-1:(5,J),J:(1,J),1:(2,1),-J:(3,J)},{-1:(5,-1),J:(4,-J),1:(2,-J),-J:(0,-J)},{-1:(0,-1),J:(1,-1),1:(4,1),-J:(3,1)},{-1:(2,J),J:(4,J),1:(5,1),-J:(0,J)},{-1:(2,-1),J:(1,-J),1:(5,-J),-J:(3,-J)},{-1:(3,-1),J:(4,-1),1:(1,1),-J:(0,1)}]))
can someone check that
[Day 23] 491 wrong p1 ```py
e=enumerate
j=1j
N={x+yj for y,l in e(open(0))for x,c in e(l)if'#'==c}
E={n:=0}
A=[-1-j,-j,1-j,1,1+j,j,j-1,-1,-1-j]
D=[A[2:5],A[:3],A[4:7],A[6:]]
while N^E:
if n==9:r,i=zip(((e.real,e.imag)for e in N));S=int((max(r)-min(r)+1)*(max(i)-min(i)+1)-len(N))
n+=1;E={*N};N=set();D=D[1:]+D[:1];P={}
for e in E:
if len(a:={i for i in A if e+i in E})and(l:=next((e+i[1]for i in D if not{*i}&a),''))!='':P[l]=*P.get(l,()),e
else:N|={e}
for l,e in P.items():N|=[{*e},{l}][len(e)==1]
print(S,n)
nice
works for me
that's good
I tried to turn the function into a lambda but couldn't get past the if elif
i might actually be able to take my partially golfed solution and golf it
nvm it's too long
β«works for me but gives WA for part 1 (fixed by doing n==10)
[Day 23] 484 ```py
e=enumerate
j=1j
N={x+yj for y,l in e(open(0))for x,c in e(l)if'#'==c}
E={n:=0}
A=[-1-j,-j,1-j,1,1+j,j,j-1,-1,-1-j]
D=[A[2:5],A[:3],A[4:7],A[6:]]
while N^E:
if n==10:r,i=zip(((e.real,e.imag)for e in N));S=int((max(r)-min(r)+1)*(max(i)-min(i)+1)-len(N))
n+=1;E={*N};N=E^E;D=D[1:]+D[:1];P={}
for e in E:
if len(a:={i for i in A if e+i in E})and(l:=next((e+i[1]for i in D if not{*i}&a),P))!=P:P[l]=*P.get(l,()),e
else:N|={e}
for l in P:N|=[{*P[l]},{l}][len(P[l])==1]
print(S,n)
[Day 23] 483 with a dangerous assumption ```py
e=enumerate
j=1j
N={x+yj for y,l in e(open(0))for x,c in e(l)if'#'==c}
E={n:=0}
A=[-1-j,-j,1-j,1,1+j,j,j-1,-1,-1-j]
D=[A[2:5],A[:3],A[4:7],A[6:]]
while N^E:
if n==10:r,i=zip(((e.real,e.imag)for e in N));S=int((max(r)-min(r)+1)*(max(i)-min(i)+1)-len(N))
n+=1;E={*N};N=E^E;D=D[1:]+D[:1];P={}
for e in E:
if len(a:={i for i in A if e+i in E})and(l:=next((e+i[1]for i in D if not{*i}&a),j))-j:P[l]=*P.get(l,()),e
else:N|={e}
for l in P:N|=[{*P[l]},{l}][len(P[l])==1]
print(S,n)
p2 doesn't work for me
[Day 23] 481 ```py
e=enumerate
j=1j
N={x+yj for y,l in e(open(0))for x,c in e(l)if'#'==c}
E={n:=0}
A=j-1,-1,-1-j,-j,1-j,1,1+j,j,j-1
D=[A[4:7],A[2:5],A[6:],A[:3]]
while N^E:
if n==10:r,i=zip(((e.real,e.imag)for e in N));S=int((max(r)-min(r)+1)*(max(i)-min(i)+1)-len(N))
n+=1;E={*N};N=E^E;D=D[1:]+D[:1];P={}
for e in E:
if len(a:={i for i in A if e+i in E})and(l:=next((e+i[1]for i in D if not{*i}&a),P))!=P:P[l]=*P.get(l,()),e
else:N|={e}
for l in P:N|=[{*P[l]},{l}][len(P[l])==1]
print(S,n)
[Day 23] 480
e=enumerate
j=1j
N={x+y*j for y,l in e(open(0))for x,c in e(l)if'#'==c}
E={n:=0}
A=j-1,-1,-1-j,-j,1-j,1,1+j,j,j-1
D=[A[4:7],A[2:5],A[6:],A[:3]]
while N^E:
if n<11:r,i=zip(*((e.real,e.imag)for e in N));S=int((max(r)-min(r)+1)*(max(i)-min(i)+1)-len(N))
n+=1;E={*N};N=E^E;D=D[1:]+D[:1];P={}
for e in E:
if len(a:={i for i in A if e+i in E})and(l:=next((e+i[1]for i in D if not{*i}&a),P))!=P:P[l]=*P.get(l,()),e
else:N|={e}
for l in P:N|=[{*P[l]},{l}][len(P[l])==1]
print(S,n)```
is E^E not the empty set?
N^E?
N=E^E in the first if statement
ah
[Day 23] 479 ```py
e=enumerate
j=1j
N={x+yj for y,l in e(open(0))for x,c in e(l)if'#'==c}
E={n:=0}
A=j-1,-1,-1-j,-j,1-j,1,1+j,j,j-1
D=[A[4:7],A[2:5],A[6:],A[:3]]
while N^E:
if n<11:r,i=zip(((e.real,e.imag)for e in N));S=int((max(r)-min(r)+1)*(max(i)-min(i)+1)-len(N))
n+=1;E={*N};N^=N;D=D[1:]+D[:1];P={}
for e in E:
if len(a:={i for i in A if e+i in E})and(l:=next((e+i[1]for i in D if not{*i}&a),P))!=P:P[l]=*P.get(l,()),e
else:N|={e}
for l in P:N|=[{*P[l]},{l}][len(P[l])==1]
print(S,n)
[Day 23] 478 ```py
e=enumerate
j=1j
N={x+yj for y,l in e(open(0))for x,c in e(l)if'#'==c}
E={n:=0}
A=j-1,-1,-1-j,-j,1-j,1,1+j,j,j-1
D=[A[4:7],A[2:5],A[6:],A[:3]]
while N^E:
if n<11:r,i=zip(((e.real,e.imag)for e in N));S=int((max(r)-min(r)+1)*(max(i)-min(i)+1)-len(N))
n+=1;E={*N};N^=N;D=D[1:]+D[:1];P={}
for e in E:
if len(a:={i for i in A if e+i in E})and(l:=next((e+i[1]for i in D if not{*i}&a),P))!=P:P[l]={*P.get(l,()),e}
else:N|={e}
for l in P:N|=[P[l],{l}][len(P[l])==1]
print(S,n)
does [{l},P[l]][len(P[l]>1] work?
yeah it should
I'm on mobile someone else do it
I can't do it rn either
!e
x = [1,2,3]
print(x)
_,*x=x+x[:1]
print(x)
@sharp scarab :white_check_mark: Your 3.11 eval job has completed with return code 0.
001 | [1, 2, 3]
002 | [2, 3, 1]
that saves another char
surely len(a:={i for i in A if e+i in E}) could just be (a:={i for i in A if e+i in E})?
!e
x,y=39,-7
print(x-y+1)
print(-y-~x)
z,w=65,9
print((x-y+1)*(z-w+1))
print((y+~x)*(w+~z))
@sharp scarab :white_check_mark: Your 3.11 eval job has completed with return code 0.
001 | 47
002 | 47
003 | 2679
004 | 2679
probably
yeah that too
we really need someone on a computer to get these changes
it used to have a >0 and I just missed that
well what if it's 0
it can't be 0
btw, it also can't be more than 2, idk if that helps with anything
I don't think that's guaranteed
only 2 elves can ever propose the same square
you can have 3 or 4 in some cases
pretty sure you can't
there are 4 elves around each square. But if there are two at right angles, they will block eachother
they only way you can have two is if they are opposite
[Day 23] 473 ```py
e=enumerate
j=1j
N={x+yj for y,l in e(open(0))for x,c in e(l)if'#'==c}
E={n:=0}
A=j-1,-1,-1-j,-j,1-j,1,1+j,j,j-1
D=[A[4:7],A[2:5],A[6:],A[:3]]
while N^E:
if n<11:r,i=zip(((e.real,e.imag)for e in N));S=int((max(r)-min(r)+1)*(max(i)-min(i)+1)-len(N))
n+=1;E={*N};N^=N;D=D[1:]+D[:1];P={}
for e in E:
if(a:={i for i in A if e+i in E})and(l:=next((e+i[1]for i in D if not{*i}&a),P))!=P:P[l]={*P.get(l,()),e}
else:N|={e}
for l in P:N|=[{l},P[l]][len(P[l])>1]
print(S,n)
is there anything else
both of mine
^
ok
[{l},P[l]][len(P[l])>1]
[0,P[l],{l}][len(P[l])] only breaks even π
[Day 23] 472 ```py
e=enumerate
j=1j
N={x+yj for y,l in e(open(0))for x,c in e(l)if'#'==c}
E={n:=0}
A=j-1,-1,-1-j,-j,1-j,1,1+j,j,j-1
D=[A[4:7],A[2:5],A[6:],A[:3]]
while N^E:
if n<11:r,i=zip(((e.real,e.imag)for e in N));S=int((max(r)-min(r)+1)*(max(i)-min(i)+1)-len(N))
n+=1;E={*N};N^=N;_,*D=D+D[:1];P={}
for e in E:
if(a:={i for i in A if e+i in E})and(l:=next((e+i[1]for i in D if not{*i}&a),P))!=P:P[l]={*P.get(l,()),e}
else:N|={e}
for l in P:N|=[{l},P[l]][len(P[l])>1]
print(S,n)
β«they're floats
oh gdi
stupid floats
well keep that optimization in mind for when we eventually switch from complex to base whatever
[Day 23] 465 ```py
e=enumerate
j=1j
N={x+yj for y,l in e(open(0))for x,c in e(l)if'#'==c}
E={n:=0}
A=j-1,-1,-1-j,-j,1-j,1,1+j,j,j-1
D=[A[4:7],A[2:5],A[6:],A[:3]]
while N^E:
if n<11:r,i=zip(((e.real,e.imag)for e in N));S=int((max(r)-min(r)+1)*(max(i)-min(i)+1)-len(N))
n+=1;E={*N};N^=N;_,*D=D+D[:1];P={}
for e in E:
if(a:={i for i in A if e+i in E})and(l:=next((e+i[1]for i in D if not{*i}&a),P))!=P:
if l in P:N|={e,P.pop(l)}
else:P[l]=e
else:N|={e}
N|={*P}
print(S,n)
[Day 23] 459
e=enumerate
j=1j
N={x+y*j for y,l in e(open(0))for x,c in e(l)if'#'==c}
E={(n:=0)}
A=j-1,-1,-1-j,-j,1-j,1,1+j,j,j-1
D=[A[4:7],A[2:5],A[6:],A[:3]]
while N^E:
if n<11:r,i=zip(*((e.real,e.imag)for e in N));S=int((max(r)-min(r)+1)*(max(i)-min(i)+1)-len(N))
n+=1;E={*N};D=D[1:]+D[:1];P={}
for e in E:
if(a:={i for i in A if e+i in E})and(l:=next((e+i[1]for i in D if not{*i}&a),P))!=P:
if l in P:del P[l]
else:P[l]=e
N|={*P};N^={*P.values()}
print(S,n)
lmao
smh
seems to be about half the speed
lmao
great minds
I am sad to see the xor-reset thing go
btw it is used in real life assembly to reset a register without loading a constant 0
[Day 23] 457 ```py
e=enumerate
j=1j
N={x+yj for y,l in e(open(0))for x,c in e(l)if'#'==c}
E={(n:=0)}
A=j-1,-1,-1-j,-j,1-j,1,1+j,j,j-1
D=[A[4:7],A[2:5],A[6:],A[:3]]
while N^E:
if n<11:r,i=zip(((e.real,e.imag)for e in N));S=int((max(r)-min(r)+1)*(max(i)-min(i)+1)-len(N))
n+=1;E={*N};D=D[1:]+D[:1];P={}
for e in E:
if(a:={i for i in A if e+i in E})and(l:=next((e+i[1]for i in D if not{*i}&a),P))!=P:
if l in P:del P[l]
else:P[l]=e
N={*P}|N^{*P.values()}
print(S,n)
oi what happened to my _,*D=D+D[:1]
i ate it
sorry
[Day 23] 456 ```py
e=enumerate
j=1j
N={x+yj for y,l in e(open(0))for x,c in e(l)if'#'==c}
E={(n:=0)}
A=j-1,-1,-1-j,-j,1-j,1,1+j,j,j-1
D=[A[4:7],A[2:5],A[6:],A[:3]]
while N^E:
if n<11:r,i=zip(((e.real,e.imag)for e in N));S=int((max(r)-min(r)+1)*(max(i)-min(i)+1)-len(N))
n+=1;E={*N};_,*D=D+D[:1];P={}
for e in E:
if(a:={i for i in A if e+i in E})and(l:=next((e+i[1]for i in D if not{*i}&a),P))!=P:
if l in P:del P[l]
else:P[l]=e
N={*P}|N^{*P.values()}
print(S,n)
should be 456
someone check
hahh
wait
I changed E={n:=0} to E={(n:=0)} because I was testing on an old version of python and forgot to remove it

your golf was just so good that despite all that it was still better
so none of us noticed
lol
tio.run. A great site but hasn't update python since 3.8 pre-release (which it only includes since the site is built for golfing, and 3.8pre is the first version with walrus)
so 454?
[Day 23] 454 ```py
e=enumerate
j=1j
N={x+yj for y,l in e(open(0))for x,c in e(l)if'#'==c}
E={n:=0}
A=j-1,-1,-1-j,-j,1-j,1,1+j,j,j-1
D=[A[4:7],A[2:5],A[6:],A[:3]]
while N^E:
if n<11:r,i=zip(((e.real,e.imag)for e in N));S=int((max(r)-min(r)+1)*(max(i)-min(i)+1)-len(N))
n+=1;E={*N};_,*D=D+D[:1];P={}
for e in E:
if(a:={i for i in A if e+i in E})and(l:=next((e+i[1]for i in D if not{*i}&a),P))!=P:
if l in P:del P[l]
else:P[l]=e
N={*P}|N^{*P.values()}
print(S,n)
if we haven't missed anything then yeah
i'm surprised ```py
if l in P:del P[l]
else:P[l]=e
is there a filler value we could fill P[l] with that wouldn't mess with the xor
that would be very cool
tbh i was very surprised it was a byte saving
with that extra level of indentation, .values and everything
[Day 23] 452 ```py
e=enumerate
j=1j
N={x+yj for y,l in e(open(0))for x,c in e(l)if'#'==c}
E={n:=0}
A=j-1,-1,-1-j,-j,1-j,1,1+j,j,j-1
D=[A[4:7],A[2:5],A[6:],A[:3]]
while N^E:
if n<11:r,i=zip(((e.real,e.imag)for e in N));S=int((max(r)-min(r)+1)*(max(i)-min(i)+1)-len(N))
n+=1;E={*N};_,*D=D+D[:1];P={}
for e in E:
if(a:={i for i in A if e+i in E})and(l:=next((e+i[1]for i in D if not{*i}&a),P))!=P:exec(("P[l]=e","del P[l]")[l in P])
N={*P}|N^{*P.values()}
print(S,n)
hah, right. nice
!e
x={i:v for i,v in zip(range(10),'abcdefghij')}
print(x)
print({*x})
@sharp scarab :white_check_mark: Your 3.11 eval job has completed with return code 0.
001 | {0: 'a', 1: 'b', 2: 'c', 3: 'd', 4: 'e', 5: 'f', 6: 'g', 7: 'h', 8: 'i', 9: 'j'}
002 | {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
k that's what I expected
[Day 23] 449
e=enumerate
j=1j
N={x+y*j for y,l in e(open(0))for x,c in e(l)if'#'==c}
E={n:=0}
A=j-1,-1,-1-j,-j,1-j,1,1+j,j,j-1
D=[A[4:7],A[2:5],A[6:],A[:3]]
while N^E:
if n<11:r,i=zip(*((e.real,e.imag)for e in N));S=int((max(r)-min(r)+1)*(max(i)-min(i)+1)-len(N))
n+=1;E={*N};_,*D=D+D[:1];P={};[exec(("P[l]=e","del P[l]")[l in P])for e in E if(a:={i for i in A if e+i in E})and(l:=next((e+i[1]for i in D if not{*i}&a),P))!=P]
N={*P}|N^{*P.values()}
print(S,n)```
[Day 23] 445 ```py
e=enumerate
j=1j
N={x+yj for y,l in e(open(0))for x,c in e(l)if'#'==c}
E={n:=0}
A=j-1,-1,-1-j,-j,1-j,1,1+j,j,j-1
D=[A[4:7],A[2:5],A[6:],A[:3]]
while N^E:
if n<11:r,i=zip(((e.real,e.imag)for e in N));S=int((max(r)-min(r)+1)*(max(i)-min(i)+1)-len(N))
n+=1;E={*N};_,*D=D+D[:1];P={};[exec(("P[l]=e","del P[l]")[l in P])for e in E if(a:={i for i in A if e+i in E})and(l:=next((e+i[1]for i in D if not{*i}&a),P))!=P];N^={*P,*P.values()}
print(S,n)
if'$'>c would work if not for newlines π
[Day 23] 433
e=enumerate
j=1j
E={x+y*j for y,l in e(open(0))for x,c in e(l)if'#'==c}
n=0
A=j-1,-1,-1-j,-j,1-j,1,1+j,j,j-1
P=D=[A[4:7],A[2:5],A[6:],A[:3]]
while P:
if n<11:r,i=zip(*((e.real,e.imag)for e in E));S=int((max(r)-min(r)+1)*(max(i)-min(i)+1)-len(E))
n+=1;_,*D=D+D[:1];P={};[exec(("P[l]=e","del P[l]")[l in P])for e in E if(a:={i for i in A if e+i in E})and(l:=next((e+i[1]for i in D if not{*i}&a),P))!=P];E^={*P,*P.values()}
print(S,n)```
rip N
if we're going to do mutability we may as well do it properly
does P[l]=[l,e][l in P] work
ooo good point
huh
oh yeah true
since deleting actually removes the key
yeah that too
[Day 23] 431
e=enumerate
j=1j
E={x+y*j for y,l in e(open(0))for x,c in e(l)if'#'==c}
n=0
A=j-1,-1,-1-j,-j,1-j,1,1+j,j,j-1
P=D=A[4:7],A[2:5],A[6:],A[:3]
while P:
if n<11:r,i=zip(*((e.real,e.imag)for e in E));S=int((max(r)-min(r)+1)*(max(i)-min(i)+1)-len(E))
n+=1;_,*D=D+D[:1];P={};[exec(("P[l]=e","del P[l]")[l in P])for e in E if(a:={i for i in A if e+i in E})and(l:=next((e+i[1]for i in D if not{*i}&a),P))!=P];E^={*P,*P.values()}
print(S,n)```
idk why you added the square brackets
nice
e=enumerate
j=1j
E={x+y*j for y,l in e(open(0))for x,c in e(l)if'#'==c}
n=0
A=j-1,-1,-1-j,-j,1-j,1,1+j,j,j-1
P=D=A[4:7],A[2:5],A[6:],A[:3]
while P:
if n<11:r,i=zip(*((e.real,e.imag)for e in E));S=int((max(r)-min(r)+1)*(max(i)-min(i)+1)-len(E))
n+=1;_,*D=D+D[:1];P={};[exec("P[l]=[e,l][l in P]")for e in E if(a:={i for i in A if e+i in E})and(l:=next((e+i[1]for i in D if not{*i}&a),P))!=P];E|={*P};E^={*P.values()}
print(S,n)```this doesn't work but I'm not sure why
don't the keys need to be removed
Yes, but if something is both a key and a value then E|={*P};E^={*P.values()} should add it and remove it again, the same as if it was not there at all
but it's while P
surely there's a better way to do A
tried range, too many chars
I was thinking using powers of (1+i) but normalizing is a pain
how do you do this without range?
well that does use range
lmao
worked for me
what did
the 427 you sent
wait what do you still have it?
bcs it was based off of this
iirc
huh
[Day 23] 423
e=enumerate
j=1j
E={x+y*j for y,l in e(open(0))for x,c in e(l)if'#'==c}
n=0
A=j-1,-1,-1-j,-j,1-j,1,1+j,j,j-1
P=D=A[4:7],A[2:5],A[6:],A[:3]
while P:
if n<11:r,i=zip(*((e.real,e.imag)for e in E))
n+=1;P={};[exec("P[l]=[e,l][l in P]")for e in E if(a:={i for i in A if e+i in E})and(l:=next((e+i[1]for i in D[n%4:]+D[:n%4]if not{*i}&a),P))!=P];E|={*P};E^={*P.values()}
print(int((max(r)-min(r)+1)*(max(i)-min(i)+1)-len(E)),n)```
and when i applied the D[n%4:]+D[:n%4] to the actual version it only broke even
I've been staring at the wrong code block this entire time lmao
yeah sorry i shouldn't post broken stuff i even confuse myself
either way i have a -4 optimization
sooo... why does this work
idk
great, i didn't look at what you did
because there won't be anyone making any propositions when the simulation stabilises
so idk why it didn't work before
maybe I just didn't wait long enough
[Day 23] 419
e=enumerate
j=1j
E={x+y*j for y,l in e(open(0))for x,c in e(l)if'#'==c}
n=0
A=j-1,-1,-1-j,-j,1-j,1,1+j,j,j-1
P=D=A[4:7],A[2:5],A[6:],A[:3]
while P:
if n<11:r,i=zip(*((e.real,e.imag)for e in E))
n+=1;P={}
for e in E:
if(a:={i for i in A if e+i in E})and(l:=next((e+i[1]for i in D[n%4:]+D[:n%4]if not{*i}&a),P))!=P:P[l]=[e,l][l in P]
E|={*P};E^={*P.values()}
print(int((max(r)-min(r)+1)*(max(i)-min(i)+1)-len(E)),n)```
shame setting n=-1 and shifting everything to compensate is worse by 1 char
[Day 22] 1109
import re,itertools as i
p,R,e,U,Q,H=i.pairwise,range,enumerate,complex,lambda z:(z.real,z.imag),zip
J=1j
S=re.findall('\d+|L|R',(F:=open(0).read().split('\n\n'))[1])
*D,=map(lambda x:(U(*x[0]),x[1]),sorted((min(map(Q,d)),d)for n,x in p(R(0,201,50))for m,y in p(R(0,151,50))if(d:={i:v for i,v in((U(x,y),v=='.')for x,r in e(F[0].split('\n'))for y,v in e(r)if v in'.#')if(n<=i.real<x)*(m<=i.imag<y)})))
L=-1,J,1,-J
def g(a):
global S,D
s,w,f=*D[c:=0],J;o=s
for v in S:
if v in'LR':f*={'L':J,'R':-J}[v];continue
for _ in R(int(v)):
if(z:=s+f)not in w:C,F=a[c][f];O,W=D[C];r,i=Q(s-o);f,o,c,w,s=eval('fF,,oO,,cC,,wW,,sz'[W[z:=O+49*U(F==-1,F==-J)+(((1-2*(b:=(F.imag>F.real)^(f.imag>f.real)))*(i if f.real else r))+49*b)*{-1:J,J:1,1:J,-J:1}[F]]::2])
elif w[z]:s=z
return int(sum(x*(y+1)for x,y in H((1000,4,1),(*Q(s),{J:-1,1:0,-J:1,-1:2}[f]))))
print(g([{i:(v,i)for i,v in H(L,j)}for j in((4,1,2,1),(1,0,1,0),(0,2,4,2),(5,4,5,4),(2,3,0,3),(3,5,3,5))]),g([{i:(v,f) for i,v,f in H(L,*j)}for j in H(((5,1,2,3),(5,4,2,0),(0,1,4,3),(2,4,5,0),(2,1,5,3),(3,4,1,0)),((J,J,1,J),(-1,-J,-J,-J),(-1,-1,1,1))*2)]))
100c removed, yay?
[Day 22] 1083
import re,itertools as i
p,R,e,U,Q,Z=i.pairwise,range,enumerate,complex,lambda z:(z.real,z.imag),zip
J,N=1j,-1
S=re.findall('\d+|L|R',(F:=open(0).read().split('\n\n'))[1])
*D,=map(lambda x:(U(*x[0]),x[1]),sorted((min(map(Q,d)),d)for n,x in p(R(0,201,50))for m,y in p(R(0,151,50))if(d:={i:v for i,v in((U(x,y),v=='.')for x,r in e(F[0].split('\n'))for y,v in e(r)if v in'.#')if(n<=i.real<x)*(m<=i.imag<y)})))
L=N,J,1,-J
def g(a):
global S,D
s,w,f=*D[c:=0],J;o=s
for v in S:
if v in'LR':f*=[J,-J][v>'M'];continue
for _ in R(int(v)):
if(z:=s+f)not in w:C,F=a[c][f];O,W=D[C];f,o,c,w,s=eval('fF,,oO,,cC,,wW,,sz'[W[z:=O+49*U(F==N,F==-J)+(((1-2*(b:=(F.imag>F.real)^(f.imag>f.real)))*Q(s-o)[f.real!=0])+49*b)*[1,J][F.real!=0]]::2])
elif w[z]:s=z
return int(sum(x*(y+1)for x,y in Z((1000,4,1),(*Q(s),{J:N,1:0,-J:1,N:2}[f]))))
print(g([{i:(v,i)for i,v in Z(L,j)}for j in((4,1,2,1),(1,0,1,0),(0,2,4,2),(5,4,5,4),(2,3,0,3),(3,5,3,5))]),g([{i:(v,f) for i,v,f in Z(L,*j)}for j in Z(((5,1,2,3),(5,4,2,0),(0,1,4,3),(2,4,5,0),(2,1,5,3),(3,4,1,0)),((J,J,1,J),(N,-J,-J,-J),(N,N,1,1))*2)]))
that's all i'm doing
at least until after aoc
is anyone doing a day 24 golf?
oh
what's bad about dfs
i couldn't store states properly with dfs because branch reasons
i didn't think about bfs because i thought the search space would grow too rapidly before finding solutions
valid states got wiped off
are there enough storms so bfs is viable?
you store (pos, time%blizzard_cycle_time)
bfs takes a bit to run but it finishes
idk try dfs
you know more about dfs and dp than me
just code in the car
that's what i did for day 15
also if you can
can you check the dimensions of your input
ah that's a shame
my input is about 90% blizzards at the start
alright, i'll probably do bfs then
for anyone else that's gonna do a golf, the board size apparently comes in either 102*35 or 152*21
maybe more idk
i'll check mine after i get to the hotel
also if you're gonna store blizzards in a dict be careful of duplicate blizzards removing each other
i just had 4 sets in my original solution
oh
for the golf i was thinking that a floodfill would be pretty short
just floodfill to all possible spots until you get to the end
then drain the pool and flood again
and do that again
also thinking about it my last two golfs were 500c and 1200c
probably shouldn't be doing first golfs anymore
mine are cursed
122*27 for me (both accounts but that might be by chance)
yeah I gave up on mine
I'll assist in golfing it tmr
ok I feel like base 200 will be better than complex for this
but I'll just use complex anyway for now
[Day 24 part 1] 320 ```py
j=1j
e=enumerate
B={(m:=~-x+~-yj,{'<':-1,'>':1,'^':-j,'v':j,'#':0,'\n':0}[c])for y,l in e(open(0))for x,c in e(l)if'.'!=c}|{(j+(E:=m-1),0),(-2j,0)}
S=-j
n=0
s={S}
while{E}-s:B={((i:=d+p).real%m.real+j(i.imag%m.imag)if d else p,d)for p,d in B};s={n for l in s for n in{l,l-1,l+1,l-j,l+j}}-{i for i,_ in B};n+=1
print(n)
does this work for everyone else?
[Day 24] 351 ```py
j=1j
e=enumerate
B={(m:=~-x+~-yj,{'<':-1,'>':1,'^':-j,'v':j,'#':0,'\n':0}[c])for y,l in e(open(0))for x,c in e(l)if'.'!=c}|{(j+m-1,0),(-2j,0)}
S=m-1,-j
n=0
for D in 1,0,1:
s={S[D]}
while{S[1-D]}-s:B={((i:=d+p).real%m.real+j(i.imag%m.imag)if d else p,d)for p,d in B};s={n for l in s for n in{l,l-1,l+1,l-j,l+j}}-{i[0]for i in B};n+=1
if D:print(n)
I'm not bothered to convert this into base-n
I think I'll go to sleep now
apparently this is also 9x faster than my original solution btw
{'<':-1,'>':1,'^':-j,'v':j,'#':0,'\n':0}[c]
[-1,1,-j,j,0,0]["<>^v#\n".index(c)]
~-x+~-y*j
x-1+y*j-j is not shorter but...
less cursed, so it's worse
[Day 24] 343 ```py
j=1j
e=enumerate
B={(m:=~-x+~-yj,[-1,1,-j,j,0,0]["<>^v#\n".index(c)])for y,l in e(open(0))for x,c in e(l)if'.'!=c}|{(j+m-1,0),(-2j,0)}
S=m-1,-j
n=0
for D in 1,0,1:
s={S[D]}
while{S[1-D]}-s:B={((i:=d+p).real%m.real+j(i.imag%m.imag)if d else p,d)for p,d in B};s={n for l in s for n in{l,l-1,l+1,l-j,l+j}}-{i[0]for i in B};n+=1
if D:print(n)
[Day 24] 333 ```py
j=1j
e=enumerate
B={(m:=~-x+~-yj,[-1,1,-j,j,0]["<>^v".find(c)])for y,l in e(open(0))for x,c in e(l)if'.'!=c}|{(j+m-1,0),(-2j,0)}
S=m-1,-j
n=0
for D in 1,0,1:
s={S[D]}
while{S[1-D]}-s:B={((i:=d+p).real%m.real+j(i.imag%m.imag)if d else p,d)for p,d in B};s={l+n for l in s for n in{0,-1,1,-j,j}}-{i[0]for i in B};n+=1
if D:print(n)
[Day 24] 324 ```py
j=1j
e=enumerate
z=-1,1,-j,j,0
B={(m:=~-x+~-yj,z["<>^v".find(c)])for y,l in e(open(0))for x,c in e(l)if'.'!=c}|{(j+m-1,0),(-2j,0)}
S=m-1,-j
n=0
for D in 1,0,1:
s={S[D]}
while{S[1-D]}-s:B={((i:=d+p).real%m.real+j(i.imag%m.imag)if d else p,d)for p,d in B};s={l+n for l in s for n in z}-{i[0]for i in B};n+=1
if D:print(n)
@sharp scarab :white_check_mark: Your 3.11 eval job has completed with return code 0.
001 | 94 62 118 60 46
002 | [('^', True), ('>', True), ('v', True), ('<', True), ('.', False)]
it doesn't?
[Day 24] 323 ```py
j=1j
e=enumerate
z=-1,1,-j,j,0
B={(m:=~-x+~-yj,z["<>^v".find(c)])for y,l in e(open(0))for x,c in e(l)if'.'!=c}|{(j+m-1,0),(-2j,0)}
S=m-1,-j
n=0
for D in 1,0,1:
s={S[D]}
while{S[1-D]}-s:B={([(i:=d+p).real%m.real+j(i.imag%m.imag),p][d==0],d)for p,d in B};s={l+n for l in s for n in z}-{i[0]for i in B};n+=1
if D:print(n)
we need #
ohh
which translates to 0
fair enough then
[Day 24] 322
j=1j
e=enumerate
z=-1,1,-j,j,0
B={(m:=~-x+~-y*j,z["<>^v".find(c)])for y,l in e(open(0))for x,c in e(l)if'.'!=c}|{(j+m-1,n:=0),(-2j,0)}
S=m-1,-j
for D in 1,0,1:
s={S[D]}
while{S[1-D]}-s:B={([(i:=d+p).real%m.real+j*(i.imag%m.imag),p][d==0],d)for p,d in B};s={l+n for l in s for n in z}-{i[0]for i in B};n+=1
if D:print(n)```
lol
why is there a space
btw is pt 2 600 greater than pt 1 for y'all?
it was 600 more on both of my accounts
not sure if coincidence or�
alright
ah ok
308 908 and 334 934 for both accounts
i thought there was a thing going on there
π
22x152 and 27x122 for input size if you were curious

