Skip to content

Instantly share code, notes, and snippets.

View gibson042's full-sized avatar

Richard Gibson gibson042

View GitHub Profile
@gibson042
gibson042 / 2021.19.js
Last active December 23, 2021 22:42 — forked from gnarf/2021.19.js
Advent of Code 2021 - Day 19 Part 2 - Console Golfing
(await(await fetch("https://adventofcode.com/2021/day/19/input")).text(Q=[])).replace(r=/.*,.*|(\d+)/g,(d,s)=>(s?Q:q).push(s?q=[]:eval(`[${d}]`)))
T=[],[...'+3+6!-!+5-7-6!+!-8-5!+8+6+8+5!-8-6-!-7-7+-7!-!-1--7!+!+8+!-7!+8+-7-8-!-7!-8-2-!+!+3+6!+!-5-7-6!-!-!-7-7+-7!+!0--8'.replace(r,t=>'+!-!!!+!!!'.slice(t))][F="flatMap"]((s,i)=>((T[i/9|0]??=[])[i%9/3|0]??=[])[i%3]=s+1|0)
M=(t,m)=>t.map(o=>m?o[D]((s,p,i)=>s+m[i]*p,0):t[F](p=>m+1?N=(n=o.l[D]((s,o,i)=>s+A(o-p.l[i]),0))>N?n:N:p[D="reduce"]((s,p,i)=>s+A(o[i]-p)**2,0)))
for(A=Math.abs,S=JSON.stringify,R=Q[N=0],R.l=[0,0,0];Q.find(q=>(t=(H=q.l?0:M(R)[F]((e,x)=>M(q)[F]((d,B)=>d[D]((c,a)=>c+e.includes(a),0)>11?[[x,B]]:[]))).length>11&&T.find(t=>H.find(([r,u])=>(V[r=S(u=R[r][F]((p,i)=>p-M(t,q[u])[i]))]|=0,++V[r]>11?U=q.l=u:0),V={})))&&q[F](P=>S(P=M(t,P)[F]((p,i)=>U[i]+p))in R[F](S)||R.push(P))););M(Q,0)
N