Last active
December 22, 2021 20:35
-
-
Save gnarf/1e2f54371c22a05b0cd3c31fc8f2be46 to your computer and use it in GitHub Desktop.
Advent of Code 2021 - Day 19 Part 2 - Console Golfing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
L=JSON.stringify | |
Z="map" | |
A=(x,y)=>Math.abs(x-y)**2 | |
X='+!!!+!!!++!!!!-!+!+!!!-!!!-+!!!!+!-!!-!+!!!!+!!++!!!+!!+!+!!!!-!!-+!!!-!-!!!-!!!+-!!!!-!-!-!!!+!!!--!!!!+!+!!+!-!!!!+!!+-!!!-!!-!-!!!!-!!--!!!+!!!-!+!+!!!+!!!++!!!!+!-!+!!!-!!!-+!!!!-!-!-!!!-!!!+-!!!!+!+!-!!!+!!!--!!' | |
for(T=[],x=0;x<X.length;)z=()=>(+eval(X[x++]+1)),T.push([[z(),z(),z()],[z(),z(),z()],[z(),z(),z()]]) | |
M=(m,t)=>m.map((_,i)=>m[0]*t[i][0]+m[1]*t[i][1]+m[2]*t[i][2]) | |
Q=[];(await(await fetch("https://adventofcode.com/2021/day/19/input")).text()).split('\n').map(i=>i.replace(/ (\d+)/,(_,n)=>(q=n,Q[n]=[])).replace(/(-?\d+),(-?\d+),(-?\d+)/,(_,x,y,z)=>Q[q].push([+x,+y,+z]))) | |
D=D=>D.map(o=>D.map(p=>A(o[0],p[0])+A(o[1],p[1])+A(o[2],p[2]))) | |
for(R=Q[0],R.l=[0,0,0];Q.filter(q=>!q.l).find(q=>{H=[] | |
for(x in (e=D(R)))for(B in (d=D(q)))d[B].filter(a=>e[x].includes(a)).length>11&&H.push([x,B]) | |
if(H.length>11){t=T.find(t=>{V={} | |
H.map(([U,u])=>{p=R[U] | |
P=M(q[u],t) | |
V[U=L([p[0]-P[0],p[1]-P[1],p[2]-P[2]])]|=0,V[U]++}) | |
for(U in V)if(V[U]>11)return 1}) | |
if(t){U=JSON.parse(U) | |
q.map(P=>{P=M(P,t) | |
P=[U[0]+P[0],U[1]+P[1],U[2]+P[2]] | |
R.every(o=>L(o)!=L(P))&&R.push(P)}) | |
return q.l=U}}});)N=0 | |
D=(a,b)=>Math.abs(a[0]-b[0])+Math.abs(a[1]-b[1])+Math.abs(a[2]-b[2]) | |
Q.map(q=>Q.map(q2=>N=Math.max(N,D(q.l,q2.l)))) | |
N |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just because I'm sure someone is interested, here is what it looked like when I submitted the answer: