#AoC 2022 | Code Golf Solutions & Spoilers

1 messages Β· Page 4 of 1

sharp scarab
#

any path inside the cube would be at most 69

#

i think

#

since any "optimal" path could just be shadowed onto the axis

sullen field
#

why does this take a few seconds

sharp scarab
#

because we're floodfilling a lot of space

orchid charm
#

because we don't check bounds at all

raw frigate
#

We're filling from the origin

sullen field
#

i'm gonna wait for 20s again and see if my changes worked

sharp scarab
#

yeah gets the right answer for me

sullen field
#

which they probably do so

raw frigate
#

And if we did 10 steps for example

#

It would reach 0,0,10

sullen field
#

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

raw frigate
#

But if there was a block in the way

sharp scarab
#

also that yeah

#

very obvious char save

raw frigate
#

It wouldn't be able to reach 0,0,10 anymore

orchid charm
orchid charm
#

how did i not see that

sharp scarab
#

you would need an input that blocks in all 3 directions

raw frigate
#

Not necessarily

orchid charm
#

like i said, you will never get such an input

raw frigate
#

Just 1 block in the wrong location would affect the result

#

Idk if it actually happens in any input

#

But it can

orchid charm
#

because then it wouldn't be a sphere

sharp scarab
#

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

orchid charm
#

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

sharp scarab
#

yeah but as you said it'd be more of a swiss cheese square and not a sphere

orchid charm
#

yeah

#

so we're all right

#

and the code works

sharp scarab
#

almost sub 200

raw frigate
#

Can we recude the constant by running the floodfill for shorter?

orchid charm
#

we probably can

raw frigate
#

How long does everyone's floodfill take

orchid charm
#

i'll try getting it to 4 digits

raw frigate
#

I think mine was 72

sharp scarab
#

huh

#

but it still works?

raw frigate
#

Idk

#

I can't test it on the current version

orchid charm
#

no we cannot reduce the constant to 4 digits

#

i tried, it's just not happening

sharp scarab
#

yeah 69 is like the minimum

raw frigate
#

How about 5 digits?

sharp scarab
#

it's at 5 digits tho

orchid charm
#

running the golf takes 11.3s for me

sharp scarab
#

takes like half a minute for me

raw frigate
#

Isn't it 118806?

orchid charm
#

hardware diff

sharp scarab
#

that's for 99

orchid charm
#

for 69 it's 57966

sharp scarab
#

I have a 6 year old mac

raw frigate
#

Ah ic

sharp scarab
#

don't expect much from it

orchid charm
#

i have a 1/2 year old mac

sharp scarab
#

actual hardware diff

#

huh cool 57966 is 6 times a prime

orchid charm
#

yeah

sullen field
orchid charm
#

they're only prime because we need to add 6 for the tips

urban torrent
#

does this take like 20s for you? Also, it's 69 for everyone? pog!

urban torrent
sharp scarab
#

that just makes it odd

#

not prime

sullen field
#

i just wish for some python assignment trick or an efforted rewrite to make a sub-200

raw frigate
#

Also, were counting surface area and not volume

sharp scarab
#

I'd bet on refactoring the neighbours bit

orchid charm
#

57966 is 6 * 9661, 57960 is 6 * a bunch of factors

sharp scarab
#

I was thinking some eval*6 trick but idk where to start with that

orchid charm
#

same with 118806 vs 118800

sullen field
#

wait i think i have an idea

sharp scarab
#

I doubt they're all prime

#

so we just got lucky

sullen field
#

just gonna wait for the 20 seconds or something that takes to run this

sharp scarab
#

lmao

orchid charm
#

at least this was better than that golf which took 2 mins

sullen field
#

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

urban torrent
orchid charm
#

oh nice

sharp scarab
#

oh very nice

sullen field
sullen field
orchid charm
#

lol

urban torrent
#

my bad

sharp scarab
#

we should go back after Christmas and tally up the amount of unexpected 69s this year

urban torrent
#

didn't understand the logic of the numbers that were %

sullen field
#

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])}

urban torrent
sullen field
#

it's too long

urban torrent
sullen field
urban torrent
#

these ones

#

what do they mean?

sharp scarab
#

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

sharp scarab
#

true

urban torrent
#

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
orchid charm
#

i thought macos came with python2

#

i must've manually installed it at some point then

urban torrent
urban torrent
urban torrent
#

i think 204/201 is the limit

orchid charm
#

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

urban torrent
orchid charm
#

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

urban torrent
urban torrent
urban torrent
#

@orchid charm any luck with the integer thingy? i'm still confused about what you were trying to explain

orchid charm
#

i was playing chess

urban torrent
#

i just started code.golf and it's amazing!

#

shortest solution to fizzbuzz, I got. How did someone 58 byte/53 character it?

sullen field
#

or python 2?

orchid charm
#

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

sullen field
orchid charm
#

?

sullen field
#

fizzbuzz in 58

orchid charm
#

uh i'll try after dinner

raw frigate
#

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!

orchid charm
#

knew it

#

πŸ™‚

raw frigate
#

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)

orchid charm
#

[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)```
sharp scarab
#

[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

urban torrent
urban torrent
raw frigate
#

what math?

#

it's just base 139

urban torrent
raw frigate
#

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

urban torrent
sharp scarab
#

no because then %b wouldn't work

#

9661 is tailored specifically for 69

urban torrent
urban torrent
wraith crypt
urban torrent
#

Can't get 58 smh

urban torrent
#

anyone golfed today?

raw frigate
#

nope

urban torrent
urban torrent
urban torrent
#

still no golfs today?

#

damn

urban torrent
sullen field
#

anyone who was at #esoteric-python at a certain time probably had 36 best

urban torrent
#

How can you POSSIBLY shave more chars?

orchid charm
#

do we just not have a day 19 golf

#

i finally did it because i was finished with exams

wraith crypt
#

I mean given that my code apparently doesn't even work for every input I'm not sure how doable that is

orchid charm
#

πŸ’€

wraith crypt
#

Day 19 seems to be a fairly ridiculous problem lol

orchid charm
#

i used z3, so…

wraith crypt
#

Lmao nice

orchid charm
#

can't golf mine either

raw frigate
#

yeah, most of the solutions on reddit aren't guaranteed for all inputs

orchid charm
#

rip

sullen field
#

who's starting with day 20 golf

raw frigate
#

I'm working on golfing mine

sullen field
#

[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))+x
1000)%f]]\nprint(m);"
exec(S+G+"A=[x*811589153 for x in A];I,=L\n"+S10+G)

orchid charm
#

[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)
raw frigate
#

[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))+x
1000)%f]]\nprint(m);"
exec(G+"A=[x
811589153 for x in A];*I,=L\n"+G[:57]*9+G)

sullen field
raw frigate
#

oh wait

raw frigate
#

off by part 1

#

lmao

sullen field
#

‫now it works for some reason (for me)

raw frigate
#

idrk

orchid charm
#

oh wait i didn't check my p2

raw frigate
#

[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))+x
1000)%f]]\nprint(m);"
exec(G+"A=[x
811589153for x in A];*I,=L;m=0\n"+G[:57]*9+G)

orchid charm
#

it's not right

#

works

sullen field
#

[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))+x
1000)%f]]\nprint(m);"
exec(G+"A=[x
811589153 for x in A];*I,=L\n"+G[:57]*9+G)

orchid charm
#

ye

raw frigate
#

yes

sullen field
#

that's weird then

#

‫"also it's supposed to be "with the space

sullen field
#

wait

sullen field
raw frigate
#

now it doesn't work anymore

#

you need to reset m between p1 and p2

orchid charm
#

now it doesn't work

#

yeah

sullen field
orchid charm
#

someone else posted another 228 which did work

#

pls repost

sullen field
#

works for me for some reason

orchid charm
#

[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

raw frigate
#

I did

orchid charm
#

so i'm just gonna repost it

raw frigate
#

smh

orchid charm
#

oh

sullen field
orchid charm
#

because the 228 also works for you

raw frigate
#

it does?

sullen field
orchid charm
#

it doesn't work for me

raw frigate
#

the base golf doesn't work

orchid charm
#

yeah

#

but it was fixed

sullen field
#

base golf doesn't even reset m

raw frigate
#

which is why it doesnt work

sullen field
#

it's quite the weird thing that it works for me

#

why am i the odd one out

raw frigate
#

why does it always have to be cereal lmao

orchid charm
#

[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)```
raw frigate
#

[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))+x
1000)%f]]for x in(1,2,3)));A=[x
811589153for x in A];*I,=L;"
exec(G+G[:57]*9+G)

orchid charm
#

[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)```
raw frigate
#

smh how did I miss that

orchid charm
orchid charm
#

πŸ’€

#

what about the 221?

sullen field
#

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
#

well of course it's off by part 1

#

you're sure that the 231 is correct?

urban torrent
orchid charm
#

but that makes it take forever

#

it might take longer than an hour

urban torrent
orchid charm
#

…

#

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

urban torrent
#

It was just quite short, so it would be golfable

orchid charm
#

πŸ’€

#

but it uses numpy

urban torrent
urban torrent
#

oh nvm

#

it's modulo

urban torrent
#

nah, nvm, that's like 230 chars

sullen field
#

otherwise it's correct for me

raw frigate
sullen field
#

off by p1

raw frigate
#

Nani?

#

Hmm

sullen field
#

why is it off by p1

raw frigate
#

yeah

sharp scarab
#

do we have a day 19 golf yet?

sharp scarab
#

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

urban torrent
#

#1050425859225436241 message

urban torrent
raw frigate
#

[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))+p
1000)%L]]for p in[1,2,3]))

sharp scarab
#

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

sharp scarab
#

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

urban torrent
orchid charm
#

works for me

sharp scarab
#

how fast is it?

orchid charm
#

within a few seconds

sharp scarab
#

because i did just basically convert my solution

orchid charm
#

like 3 seconds

sharp scarab
#

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

orchid charm
#

[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)```
sharp scarab
#

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

orchid charm
#

[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]))```
sullen field
#

relooked at day 20 and it seems like everything's all correct

orchid charm
sullen field
#

it took 17 hours to find that out

orchid charm
#

could've shaved 13 hours off that time if you'd checked when i asked

sullen field
#

[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(C
26)
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(C
4)
print(max(z.values()),max(b+d
(a&c<1)for a,b in r for c,d in r))

orchid charm
#

how did we not see that

sharp scarab
#

I feel bad for whoever has to gather up all the golfs and put them in the github

#

we're 9 days behind

orchid charm
#

uh oops

#

that was supposed to be me and tessa

#

i had exams, will probably do it tomorrow

sharp scarab
#

she had exams so she handed it over to people that also have exams

sullen field
sharp scarab
#

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

raw frigate
#

my christmas break starts in 2 days

orchid charm
#

same

#

but i'm done with exams

#

had my last one today

raw frigate
#

my exams are in like may

#

but I have mocks right after the break

orchid charm
#

as well as search within forum posts

sharp scarab
#

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

raw frigate
#

we need to make lancebot keep track of the golfs

#

and have them accessible through a command

sharp scarab
#

golfhelper for next year?

raw frigate
#

yeah maybe

sharp scarab
#

if yall are still here next year

raw frigate
#

yeah I probably will

sharp scarab
#

same

orchid charm
#

really depends on how school is

#

if i forget how to manage my time, probably won't be here next year

urban torrent
sharp scarab
#

nah I mean like a helper to assist with submitting golfs

#

not like an actual golf helper

sullen field
#

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

raw frigate
#

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

raw frigate
#

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

sullen field
sullen field
#

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

urban torrent
sullen field
urban torrent
sullen field
#

i've tried changing it to some shorter variable before

urban torrent
#

[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}")
wraith crypt
#

Invalid syntax

urban torrent
#

how

wraith crypt
urban torrent
wraith crypt
#

It seems to be evaling a string with colons in it

#

What version are you using?

urban torrent
urban torrent
wraith crypt
#

Doesn't work in 3.10.2 either

urban torrent
#

if not, the problem has propagated below

wraith crypt
#

Wait hold on

#

I messed up the C&P because of how neovim works -_- ignore me

urban torrent
#

[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))
steep swift
#

[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))```
wraith crypt
#

Yeah it gives the right answer when I run the right code

#

πŸ™ƒ

urban torrent
wraith crypt
#

WA

#

OBOE

urban torrent
wraith crypt
#

Not sure what it's doing to get the wrong answer but it's the wrong answer

urban torrent
steep swift
#

[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))
wraith crypt
#

It's an FPE LMAO

urban torrent
wraith crypt
#

Floating-point error

sullen field
urban torrent
#

lol ok

wraith crypt
#

220 works though

urban torrent
wraith crypt
#

They should be inted yeah

#

(or in this case rounded)

urban torrent
#

[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))
wraith crypt
#

218, use round

urban torrent
wraith crypt
#

(same problem as previous 218 -> 220)

urban torrent
wraith crypt
sullen field
#

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

wraith crypt
urban torrent
#

I still don't understand how the real/imag thingy works though.

#

seems like magic to me'

wraith crypt
#

It calculates a complex answer a - bi where a / b is the correct answer

urban torrent
#

and why is root root?

#

and how is root() even working?

cyan lynx
#

a friend did 206 but he is just joining the server now

wraith crypt
#

It appears to be transpiling the input into a set of lambdas

#

Then running the one for root

sullen field
#

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

echo quartz
echo quartz
#

I tried to replace root with R, but no gain 😦

urban torrent
#

Welcome to the server! πŸ˜„

#

..: wot-

echo quartz
#

Welcome, I used to perl golf in good old times, I still claim that perl is much better for golfing πŸ˜‰

wraith crypt
#

(please use the format though)

urban torrent
#

the regexes are insane

sullen field
#

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}")

urban torrent
sullen field
#

i mean the minus in the real code

wraith crypt
#

It's comparing a and b

sullen field
#

ok

echo quartz
urban torrent
wraith crypt
#

Or that

urban torrent
wraith crypt
#

.0f does the rounding

urban torrent
echo quartz
urban torrent
sullen field
wraith crypt
sullen field
steep swift
#

[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))
sullen field
#

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

wraith crypt
#

Well that's disappointing

sullen field
scarlet grove
#

different 192, but skipping the int() and assuming that only root starts with ro

sullen field
urban torrent
echo quartz
scarlet grove
#

works for my input πŸ˜›

sullen field
echo quartz
steep swift
#

@scarlet grove raw is not required for the first string on line 4

scarlet grove
echo quartz
#

OK, it was nice to meet you, I have to leave for now, I'll drop later to see your sub 100 πŸ˜‰

sullen field
#

why do you have to be different

urban torrent
wraith crypt
#

Lmao

sullen field
#

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

wraith crypt
#

2116 here

sullen field
wraith crypt
#

Lmao

scarlet grove
#

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))```
sullen field
urban torrent
#

so which one works for all inputs?

sullen field
urban torrent
#

for the last line

sullen field
#

o

#

fixed

sullen field
#

nice

urban torrent
#

real/imag is the slope of a complex number. wish there was a function for that πŸ˜”

urban torrent
sharp scarab
#

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

urban torrent
#

which will increase char length

raw frigate
#

if only you could just unpack real and imag values like a tuple

sharp scarab
#

atan2 is just arctan with its range modified to fit convention

sharp scarab
#

and complex ints

scarlet grove
# urban torrent what? i don't get it

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

echo quartz
sullen field
echo quartz
sullen field
#

‫so it's literally just loading the variable every time the variable is referenced

steep swift
#

[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))
sullen field
#

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

urban torrent
#

remind me what \2 was?

sullen field
#

‫i'm currently working on a one-exec version

urban torrent
echo quartz
#

When replacing operator to minus in root=v1 op v2 he takes a chance to also replace root with R - very clever

sullen field
urban torrent
echo quartz
sullen field
#

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

sharp scarab
#

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

urban torrent
#

[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))
sullen field
#

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

echo quartz
#

I'm pretty sure we don't need that t anymore, just cannot implement this

urban torrent
sullen field
sharp scarab
#

lmao

sullen field
#

i thought he was the one that did root() but it turns out i had it partially done on my text editor

sharp scarab
#

I have no idea what the golf is btw I'm still doing my day 21

#

would golf but hotel has shit internet

sullen field
urban torrent
#

back to 176

sullen field
urban torrent
sullen field
#

‫humn updated code

sullen field
#

day 20 didn't even go that far

#

it's still 11 bytes away

sharp scarab
#

it's shorter than day 3

sharp scarab
sullen field
sharp scarab
#

the github says day 3 is 201

urban torrent
sullen field
sharp scarab
#

is there a shorter golf floating around?

urban torrent
sullen field
urban torrent
#

shortest is 156

sharp scarab
#

ah ok

#

i only joined the threads like day 9

sharp scarab
#

does it fail on some inputs

urban torrent
#

some FPE

sharp scarab
#

ah

sharp scarab
#

what original operator do you guys have for root?

sharp scarab
#

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

orchid charm
#

wtf happened while i was asleep

#

y'all took my idea and ran with it lol

sharp scarab
#

see this is why we need u here next year

#

u come up with the good golf ideas

sharp scarab
#

[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))
echo quartz
orchid charm
#

yeah

echo quartz
echo quartz
orchid charm
sharp scarab
#

extra semicolon?

orchid charm
#

i think, at least

echo quartz
sharp scarab
#

yeah

#

mine needs the semicolon at the end

orchid charm
#

without the semicolon you need a trailing newline

echo quartz
#
$ 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
sharp scarab
#
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
orchid charm
#

y'all this is because of the trailing newline or lack thereof

echo quartz
#

Well, I'm getting input with wget - so the question is whos input.txt is wrong?

sharp scarab
#

we usually do no trailing newline i think

orchid charm
#

yeah

sharp scarab
#

apparently that's what aoc does

echo quartz
#
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
orchid charm
#

wasn't my decision

echo quartz
#

Is it curl adding missing newline at the end?

sharp scarab
#

idk

#

i just copy and paste to a txt file

echo quartz
#

Are there any rules for the golf? I think that should be clarified

orchid charm
#

yeah, we have inputs without trailing newlines for golfing

#

even though the actual inputs do have trailing newlines (at least for me)

echo quartz
#

ok, a bit strange but ACK

sharp scarab
#

we've had this issue before

orchid charm
sharp scarab
#

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

echo quartz
sharp scarab
#

you'd need complex ints as well

#

or gaussian ints would be the proper name for it

echo quartz
#

BTW, if the answer is 123 then is 123.0 correct? Would aoc accept it or not?

sharp scarab
#

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

echo quartz
#

But it wouldn't work for today, as we had non-integer divisions?

sharp scarab
#

yeah

#

i mean just in general

urban torrent
echo quartz
echo quartz
# urban torrent

Yep, we discussed it - I have input.txt with final newline, as for some reason the rule is it shouldn't be there.

urban torrent
echo quartz
#

...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?

wraith crypt
#

printf "$(cat INPUT_FILE)" | py my_program.py should do it

#

I think

sharp scarab
echo quartz
#

Well... Nobody even tries today's task?

sharp scarab
#

I haven't done it yet lmao

#

behind as usual

echo quartz
sharp scarab
#

I'm in jst rn

#

but since I'm on holiday I'm like away for most of the day

urban torrent
#

I recently discovered code.golf. Really fun website. Have been doing a few of their problems in the last few days.

orchid charm
#

so i couldn't

#

actually i'll be traveling for the next few days

#

up until end of advent

echo quartz
#

Strange. Looks like there's a life beyond AoC?

sharp scarab
#

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

sharp scarab
#

yeah even just my parsing is 347 characters lmao

sharp scarab
#
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

sharp scarab
#

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

raw frigate
#

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

sharp scarab
#

ah yes

raw frigate
#
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
sharp scarab
#

good ol' if n==9: ... #do part 1 here

#

great for golfing

#

reduces the character count drastically

raw frigate
#

yeah

#

I made it do part 2 but it breaks on actual input for whatever reason

orchid charm
#

should use if n==9:0

#

to save chars

raw frigate
#

I'll take a look later to see what the problem is

sharp scarab
#

i'm still debugging my "golfed" day 22

raw frigate
#

but idk what makes it work for example but not actual

sharp scarab
#

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

orchid charm
#

lol

sharp scarab
#

bruh

#

my table was wrong this entire time

raw frigate
#

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

sharp scarab
#

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

raw frigate
#

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

sharp scarab
#

nice

sharp scarab
#

that's good

sharp scarab
sullen field
#

nvm it's too long

sullen field
#

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

raw frigate
# sullen field [Day 23] 484 ```py e=enumerate j=1j N={x+y*j for y,l in e(open(0))for x,c in e(l...

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

orchid charm
#

[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)```
sharp scarab
#

is E^E not the empty set?

raw frigate
#

N^E?

sharp scarab
#

N=E^E in the first if statement

raw frigate
#

oh

#

yeah

#

we need to clear N

sharp scarab
#

ah

sullen field
#

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

sharp scarab
#

does [{l},P[l]][len(P[l]>1] work?

raw frigate
#

yeah it should

sharp scarab
#

I'm on mobile someone else do it

raw frigate
#

I can't do it rn either

sharp scarab
#

!e

x = [1,2,3]
print(x)
_,*x=x+x[:1]
print(x)
tawny dawnBOT
#

@sharp scarab :white_check_mark: Your 3.11 eval job has completed with return code 0.

001 | [1, 2, 3]
002 | [2, 3, 1]
sharp scarab
#

that saves another char

lapis rover
#

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})?

sharp scarab
#

!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))
tawny dawnBOT
#

@sharp scarab :white_check_mark: Your 3.11 eval job has completed with return code 0.

001 | 47
002 | 47
003 | 2679
004 | 2679
sharp scarab
#

probably

sharp scarab
#

we really need someone on a computer to get these changes

raw frigate
#

it used to have a >0 and I just missed that

sullen field
raw frigate
#

it can't be 0

sharp scarab
#

it's for stuff in P

#

if it was 0 it wouldn't be in P I think

lapis rover
#

btw, it also can't be more than 2, idk if that helps with anything

raw frigate
#

I don't think that's guaranteed

lapis rover
#

only 2 elves can ever propose the same square

raw frigate
#

you can have 3 or 4 in some cases

lapis rover
#

pretty sure you can't

raw frigate
#

oh wait

#

yeah

lapis rover
#

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

sullen field
#

[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

sharp scarab
#

both of mine

sullen field
#

ok

lapis rover
#

[{l},P[l]][len(P[l])>1]
[0,P[l],{l}][len(P[l])] only breaks even πŸ˜”

sullen field
#

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

sullen field
sharp scarab
#

oh gdi

#

stupid floats

#

well keep that optimization in mind for when we eventually switch from complex to base whatever

raw frigate
#

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

lapis rover
#

[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)
sharp scarab
#

lmao

raw frigate
#

smh

lapis rover
#

seems to be about half the speed

#

lmao

#

great minds

#

I am sad to see the xor-reset thing go

sharp scarab
#

rip xor reset

#

you will be missed

lapis rover
#

btw it is used in real life assembly to reset a register without loading a constant 0

sharp scarab
#

shame you can't subtract dictionaries

#

huh

#

TIL

raw frigate
#

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

sharp scarab
#

oi what happened to my _,*D=D+D[:1]

orchid charm
#

i ate it

sharp scarab
#

damn

#

stop eating our golfs

orchid charm
#

sorry

sharp scarab
#

[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

lapis rover
#

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

sharp scarab
#

your golf was just so good that despite all that it was still better

#

so none of us noticed

lapis rover
#

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)

sullen field
#

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)

sharp scarab
#

if we haven't missed anything then yeah

sullen field
#

i'm surprised ```py
if l in P:del P[l]
else:P[l]=e

lapis rover
#

it's because only two elves can propose the same move

#

as discussed previously

sharp scarab
#

is there a filler value we could fill P[l] with that wouldn't mess with the xor

lapis rover
#

that would be very cool

#

tbh i was very surprised it was a byte saving

#

with that extra level of indentation, .values and everything

sullen field
#

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

lapis rover
#

hah, right. nice

sharp scarab
#

!e

x={i:v for i,v in zip(range(10),'abcdefghij')}
print(x)
print({*x})
tawny dawnBOT
#

@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}
sharp scarab
#

k that's what I expected

orchid charm
#

[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)```
sullen field
#

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

lapis rover
#

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)```
sharp scarab
#

rip N

lapis rover
#

if we're going to do mutability we may as well do it properly

sharp scarab
#

does P[l]=[l,e][l in P] work

lapis rover
#

ooo good point

orchid charm
#

not terminating when i run

#

with P[l]=[l,e][l in P]

sharp scarab
#

huh

lapis rover
#

should be e,l i think

#

oh nah i don't think it's valid

sharp scarab
#

oh yeah true

lapis rover
#

since deleting actually removes the key

sharp scarab
#

yeah that too

lapis rover
#

buuut

#

maybe if we separate the add and remove again

#

since its quite a big saving

orchid charm
#

[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

lapis rover
#

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
orchid charm
#

don't the keys need to be removed

lapis rover
#

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

orchid charm
#

but it's while P

lapis rover
#

ahhh

#

right

#

thanks

sharp scarab
#

surely there's a better way to do A

orchid charm
#

tried range, too many chars

sharp scarab
#

I was thinking using powers of (1+i) but normalizing is a pain

orchid charm
sharp scarab
#

well that does use range

orchid charm
#

yeah

#

i tried the same

#

but too many chars

lapis rover
#

wait no

#

i'm editing the wrong version

sharp scarab
#

lmao

orchid charm
#

worked for me

lapis rover
#

what did

orchid charm
#

the 427 you sent

lapis rover
#

wait what do you still have it?

orchid charm
#

yeah

#

i made it better too

lapis rover
#

iirc

sharp scarab
#

huh

orchid charm
#

[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)```
lapis rover
#

and when i applied the D[n%4:]+D[:n%4] to the actual version it only broke even

sharp scarab
#

I've been staring at the wrong code block this entire time lmao

lapis rover
#

yeah sorry i shouldn't post broken stuff i even confuse myself

orchid charm
#

either way i have a -4 optimization

orchid charm
#

idk

lapis rover
#

oh actually no

#

it should work

orchid charm
#

great, i didn't look at what you did

lapis rover
#

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

orchid charm
#

[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)```
sharp scarab
#

shame setting n=-1 and shifting everything to compensate is worse by 1 char

sharp scarab
#

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

sharp scarab
#

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

orchid charm
#

haven't even done day 24 yet

#

it's just dfs with pruning, isn't it?

sharp scarab
#

i tried dfs

#

it sucked

#

bfs is better

orchid charm
#

oh

sharp scarab
#

or maybe i'm just bad at dfs

#

that's definitely possible as well

orchid charm
#

what's bad about dfs

sharp scarab
#

i couldn't store states properly with dfs because branch reasons

orchid charm
#

i didn't think about bfs because i thought the search space would grow too rapidly before finding solutions

sharp scarab
#

valid states got wiped off

orchid charm
#

are there enough storms so bfs is viable?

sharp scarab
#

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

orchid charm
#

maybe after i get to the next hotel

#

am on the road rn

sharp scarab
#

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

orchid charm
#

not logged in on phone

#

i also can't use a hotspot

sharp scarab
#

ah that's a shame

sharp scarab
cold dagger
#

my queue size for bfs doesn't go past 3000

#

total ~120,000 states searched

sharp scarab
#

i was gonna golf today

#

but it's a real pain

orchid charm
sharp scarab
#

for anyone else that's gonna do a golf, the board size apparently comes in either 102*35 or 152*21

#

maybe more idk

orchid charm
#

i'll check mine after i get to the hotel

sharp scarab
#

also if you're gonna store blizzards in a dict be careful of duplicate blizzards removing each other

orchid charm
#

that's why you store blizzard direction in the key

#

obviously

sharp scarab
#

i just had 4 sets in my original solution

orchid charm
#

oh

sharp scarab
#

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

sharp scarab
#

probably shouldn't be doing first golfs anymore

#

mine are cursed

raw frigate
#

I started on one earlier

#

should I keep going with it?

raw frigate
sharp scarab
#

I'll assist in golfing it tmr

raw frigate
#

ok I feel like base 200 will be better than complex for this

#

but I'll just use complex anyway for now

sharp scarab
#

we can always convert to base 200

#

complex is easier to debug tho

raw frigate
#

yeah

#

that's why I'm sticking with it for now

raw frigate
#

[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

lapis rover
#

{'<':-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...

orchid charm
raw frigate
sullen field
sullen field
sharp scarab
#

wtf

#

!e

print(*map(ord,'^>v<.'))
print([(i,i>'2') for i in '^>v<.'])
tawny dawnBOT
#

@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)]
sharp scarab
#

there we go

#

replace '.'!=c with '2'>c

#

actually I could just do it

sullen field
#

have you tested it

#

because it doesn't work

sharp scarab
#

it doesn't?

sullen field
#

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

sullen field
sharp scarab
#

ohh

sullen field
#

which translates to 0

sharp scarab
#

fair enough then

orchid charm
#

[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

sharp scarab
#

why is there a space

orchid charm
#

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…?

sharp scarab
#

mine was 518 more

#

probably a coincidence

orchid charm
#

alright

sharp scarab
#

is the space just a discord thing

orchid charm
#

yeah

#

the while should be under the for

#

so it should all be indented

sharp scarab
#

ah ok

orchid charm
#

308 908 and 334 934 for both accounts

#

i thought there was a thing going on there

#

πŸ˜”

sharp scarab
#

even if it did hold

#

we'd lose like 10-20c

#

I think

#

not that much

orchid charm
#

22x152 and 27x122 for input size if you were curious