You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
k/w.c

74 lines
8.6 KiB

#include"a.h" // ngn/k, (c) 2019-2022 ngn, GNU AGPLv3 - https://codeberg.org/ngn/k/raw/branch/master/LICENSE
S A2(dec,/*01*/K2("0{z+x*y}/",x,y))
S A2(enc,/*01*/Q(xtzZ)P(x==ai(2)&&ytz&&gl_(y)<0,x=rsz(64,xR);x(enc(x,y)))K2("{$[0>&/x;`err\"domain\";x~*x;[$[0|/*y:x!|![-x;]\\y;@[y;0;-:0<];1_y]];x!'|(,y),y{(-y)!x}\\|1_x]}",x,y))
S A scC(Cc ,C*p,Ln)_( Ax=oA;C*q;W((q=MC(p,c,n )),xq(aCm(p,q));n-=q-p+1;p=q+1)I(n||c-10&&xn,xq(aCn(p,n)))x)S A sc(Cc ,Ax)_(XC(x(scC(c, xV,xn)))et1(x))A1(spl,sc(10,x))
S A sCC(C*s,Lm,C*p,Ln)_(P(!m,el0())Ax=oA;C*q;W((q=MM(p,n,s,m)),xq(aCm(p,q));n-=q+m-p;p=q+m)I(n|| xn,xq(aCn(p,n)))x)S A sC(C*s,Lm,Ax)_(XC(x(sCC(s,m,xV,xn)))et1(x))
S L jN(Lm,Ax/*0*/)_(P(!xtA,-1)Ln=(xn-!!xn)*m;i(xn,Ay=xa;P(!ytcC,-1)n+=yN)n)//total length or -1
A jc(Cc, Ax)_(XC(jc(c, flp(flp(x))))Ln=jN(1,x);P(n<0,et1(x))Ay=aC(n);C*p=yV;i(xn,I(i,*p++=c )Az=xa;I(ztc,*p++=zv)E(Mc(p,zV,zn);p+=zn))x(y))
A jC(Qs,Nm,Ax)_(XC(jC(s,m,flp(flp(x))))Ln=jN(m,x);P(n<0,et1(x))Ay=aC(n);C*p=yV;i(xn,I(i,Mc(p,s,m);p+=m)Az=xa;I(ztc,*p++=zv)E(Mc(p,zV,zn);p+=zn))x(y))
L cfm(OA*a/*0*/,In)_(Lm=-1;i(n,Ax=a[i];I(!xtt,Lv=xN;P(m>=0&&m-v,-2)m=v))m)
S I arf2(A2 f)_((SZ(V*)-8?fI:fL)(v2+1,10,(L)f)!=NL)S A1(re0,rs0(enl(x)))
S A o1f(A1 f,Ax/*f1*/)_(f==len?x(ai(0)):f==str?x(oC):f==cS||f==enl?f(x):x)S A o2f(A2 f,Ax,Ay/*f01*/)_(f==bng?y(ai(0)):arf2(f)||f==hsh||f==cst?f(x,y):y(oC))
S A2(o1,/*01*/xtu?o1f(v1[xv],y):y(oC))S A3(o2,/*001*/xtv?o2f(v2[xv],y,z):z(oC))
S AX(em,/*01..1*/Az=oS;Ik=0;i(n,Ay=a[i];I(ytm,k++;z=cat11(z,_R(yx))))I(k>1,z=unq(z))Ab8;i(n,Ay=b[i]=a[i];I(ytm,Au=kv(&y);uq(ie(x,u));b[i]=u(u1(y(fil(ai(yn),fnd(y,zR)))))))AX e8;x=Nz(e8(x,b,n));z(dct(z,x)))
A e1f(A1 f,Ax)_(Xt(f(x))Xm(Ay=kv(&x);am(x,Nx(e1f(f,y))))Nn=xN;P(!n,re0(N(o1f(f,fir(x)))))
I b=xtA&&xr==1;Ay=aA0(n);i(n,Az=f(b?xa:ii(x,i));B(!z,I(b,mrn(xn-i-1,xA+i+1))y=y(0))yq(z))I(b,x=AZ(x))x(y))
S A2(e1,/*01*/Xu(e1f(v1[xv],y))Yt(x1(y))Ym(em(x,&y,1))Nm=yN;P(!m,re0(N(o1(x,fir(y)))))P(ytA&&yr==1,y=AZ(y);Au=oA;i(m,Az=x1(ya);B(!z,u=u(0);mrn(m-i-1,yA+i+1))uq(z))y(u))
Au=oA;i(m,Az=x1(ii(y,i));B(!z,u=u(0)) uq(z))y(u))
A l2f(A2 f,Ax,Ay/*f01*/)_(Xt(f(x,y))Xm(Az=N(l2f(f,xy,y)); am(_R(xx),z) )Nn=xN;P(!n, re0(N(o2f(f,x,fir(y)))))Au=aA0(n);i(n,A w=ii(x,i),v=f(w,yR);mr(w); B(!v,u=u(0))u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,x8(a,n))i(n,I(t[i]==1,_r(a[i])+=m))Au=0;I(!m,u=x==LEN?oB:n==2&&xtv&&xv<11?_R(a[!_N(a[1])]):oA)//t[i] 0:pkdatm,1:refatm,2:tA(r=1),3:tA,4:other
j(m,i(n,Ay=a[i];I(t[i]==2,b[i]=yA[j])I(t[i]>2,b[i]=ii(y,j)))Az=x8(b,n);B(!z,I(u,u=u(0))i(n,Ay=a[i];I(t[i]==1,yr-=m-j-1)I(t[i]==2,mrn(m-j-1,yA+j+1))))I(!j,u=LH(ti,zt,ts)?AN(0,an(m,TT[zt])):oA)uq(z))
i(n,mr(t[i]-2?a[i]:AZ(a[i])))u)
A e2f(A2 f,Ax,Ay/*f01*/)_(Ik=2*xtt+ytt;P(k==3,f(x,y))
P(xtm||ytm,P(xtm>ytm,Az=N(e2f(f,xy,y));am(_R(xx),z))P(xtm<ytm,Az=Ny(e2f(f,x,_R(yy)));y(am(_R(yx),z)))
Az=unq(cat(xx,_R(yx)));x=x1(zR);y=y(y1(zR));I(arf2(f),Au=ai(f==mul||f==dvd);x=fil(u,x);y=fil(u,y))am(z,Nz(x(e2f(f,x,y)))))
P(!k&&xN-yN,el1(y))Nn=k<2?xN:yN;P(!n,x=fir(xR);re0(N(x(o2f(f,x,fir(y))))))Az=oA;i(n,A v=ii(x,i);Au=f(v,ii(y,i));mr(v);B(!u,z=z(0))zq(u))y(z))
S A2(cs,/*01*/Az,v=yR,u=enl(yR);W(1,z=yR;y=x1(y);P(!y,mr(v);z(u(0)))Im=mtc_(y,z)||mtc_(y,v);z(0);B(m)uq(yR))mr(v);y(u))
S A2(cf,/*01*/Az=yR,u;W(1,zR;u=x1(z);B(!u)P(mtc_(u,y)||mtc_(u,z),y(u(z)))z=z(u))y(z(u)))
S A ns(Ax,Lm,Ay/*0m1*/)_(Az=aA0(m+1);i(m,zq(yR);y=x1(y);B(!y))y?zq(y):z(y))
S A nf(Ax,Lm,Ay/*0m1*/)_(i(m,y=N(x1(y)))y)
S A3(ws,/*001*/Au=enl(zR);W(1,A w=y1(zR);B(!w,u=u(0))B(!tru(w))z=x1(z);P(!z,u(0))uq(zR))z(u))
S A3(wf,/*001*/Au=0;W(1,A w=y1(zR);B(!w,z=z(0))B(!tru(w))z=x1(z);P(!z,0))z)
S A nS(Ax,Lm,OA*a,Nn/*0m1n*/)_(P(n==1,ns(x,m,*a))m=max(0,m);Az=aA(n+m),*b=zV;zn=n;Mc(b,a,8*n);i(m,mRn(n,b);b[n]=Nz(x8(b,n));zn++;b++)sqz(z))
S A wS(Ax,Ay,OA*a,Nn/*001n*/)_(P(n==1,ws(x,y,*a))Ab8;Mc(b,a,8*n);mRn(n,b);Az=sqz(aV(tA,n,b));
W(1,Au=y1(ii(z,zn-1));B(!u,z=z(0))B(!tru(u))mRn(n-1,b+1);u=x8(b,n);B(!u,*b=au;z=z(0))Mm(b,b+1,8*n-8);b[n-1]=u;zq(uR))mrn(n,b);z)
S A nF(Ax,Lm,OA*a,Nn/*0m1n*/)_(P(n==1,nf(x,m,*a))las(N(nS(x,m,a,n))))
S A wF(Ax,Ay,OA*a,Nn/*001n*/)_(P(n==1,wf(x,y,*a))las(N(wS(x,y,a,n))))
S A3(ls2,/*010*/Yz(ns(x,gl(y),zR))YU(y(ws(x,y,zR)))et1(y))
S A3(lf2,/*010*/Yz(nf(x,gl(y),zR))YU(y(wf(x,y,zR)))et1(y))
S AX(ls8,/*01..1*/Ay=*a;P(n==2,Az=a[1];z(ls2(x,y,z)))Yz(nS(x,gl(y),a+1,n-1))YU(y(wS(x,y,a+1,n-1)))et8(a,n))
S AX(lf8,/*01..1*/Ay=*a;P(n==2,Az=a[1];z(lf2(x,y,z)))Yz(nF(x,gl(y),a+1,n-1))YU(y(wF(x,y,a+1,n-1)))et8(a,n))
A1(raz,XA(Nn=0;i(xn,n+=_N(xa))Ay=xx;y=ytT&&!ytA?AN(0,an(n,yt)):aA0(n);i(xn,y=cat11(y,_R(xa)))x(y))Xm(raz(val(x)))x)
S A2(f1,/*01*/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yR))mrn(n,a);y(z))
S A3(p2,/*010*/ Zt(er1(y))Zm(y=N(p2(x,y,zy));am(_R(zx),y))P(!zN,y(zR))P(xtv&&xv<11&&ytzc&&ztZC,arp(x,y,z))Au=aA0(zN);i(zN,A v=ii(z,i),r=x2(v,y);y=v;B(!r,u=u(0))uq(r))y(u))
S A2(p1,/*01*/y(p2(x,ie(x,y),y)))
S A stn(Ax,Ln,Ay/*0n0*/)_(P(n<0||n-(I)n,ed0())P(!ytT,et0())Lm=max(0,yn-n+1);Az=aA0(m);P(!m,mr(zx);zx=mkn(rsz(n,fir(yR)));z)i(m,zq(Nz(x1(slc(y,i,i+n)))))z)
S A3(ste,/*010*/Yz(stn(x,gl(y),z))et1(y))S ALA(win,x(stn(au,n,x)))
S A2 binF;
S A2(binZ,/*01*/Q(xtZC)
YZC(P(xn-(I)xn,ez1(y))I wx=xw,wy=yw;P(!wx,wy?K2("{@[x'`c$127&y;&-128>y;:;-1]}",x,y):K2("{(-1+\\@[&256;128+x;+;1])128+y}",x,y))Az=an(yn,tZ(xn-1));I wz=zw,k[2];
i(yn,Lv;S4(wy,v=yb,v=yh,v=yi,v=yl)*k=-1;k[1]=xn;S4(wx,,W(*k+1<k[1],Ii=*k+k[1]>>1;k[v<xh]=i),W(*k+1<k[1],Ii=*k+k[1]>>1;k[v<xi]=i),W(*k+1<k[1],Ii=*k+k[1]>>1;k[v<xl]=i))
S4(wz,zb=*k,zh=*k,zi=*k,zl=*k))y(z))
YF(x=cF(xR);x(binF(x,y)))Yt(YU(ed1(y))fir(N(binZ(x,enl(y)))))YmMA(r2f(binZ,x,y))ed1(y))
S A2(binF,/*01*/Q(xtF)YF(x=of1(xR);x(binZ(x,of1(y))))YZC(binF(x,N(cF(y))))Yt(YU(ed1(y))fir(N(binF(x,enl(y)))))YmMA(r2f(binF,x,y))ed1(y))
S A2(bin,/*01*/XZC(binZ(x,y))XF(binF(x,y))Xm(_1(xx,N(bin(xy,y))))et1(y))
A2(w1,/*01*/Q(xtr)Ii=xE;x=xx;SW(i,CR(0,Xt(e1(x,y))bin(x,y))CR(1,P(xtzZ||xtfF,dec(x,y))Xc(jc(xv,y))XC(jC(xV,xn,y))P(xK<2,cf(x,y))f1(x,y))
CR(2,XfF(en1(y))XzZ(enc(x,y))Xc(sc(xv,y))XC(sC(xV,xn,y))P(xK<2,cs(x,y))s1(x,y))CR(3,Xz(win(gl_(x),y))p1(x,y))CR(4,er1(y))CR(5,e1(x,y)))en1(y))
A3(w2,/*010*/Q(xtr)Ii=xE;x=xx;SW(i,CR(0,y(e2(x,y,zR)))CR(1,(xK<2?lf2:f2)(x,y,z))CR(2,(xK<2?ls2:s2)(x,y,z))CR(3,(xK==1?ste:p2)(x,y,z))CR(4,y(r2(x,y,zR)))CR(5,y(l2(x,y,zR))))en1(y))
AX(w8,/*01..1*/Q(xtr)Ay=*a;P(n==1,w1(x,y))P(n==2,Az=a[1];z(w2(x,y,z)))Ii=xE;x=xx;SW(i,CR(0,e8(x,a,n))CR(1,P(xK<2||n-xK==1,lf8(x,a,n))f8(x,a,n))
CR(2,P(xK<2||n-xK==1,ls8(x,a,n))s8(x,a,n))CR(3,er8(a,n))CR(4,er8(a,n))CR(5,l8(x,a,n)))en8(a,n))