Advertisement
Romanok2805

Untitled

Aug 20th, 2019
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 25.18 KB | None | 0 0
  1. local a={}local b={[0]={0,0,0,0,0,0,0,0},{1,0,0,0,0,0,0,0},{0,1,0,0,0,0,0,0},{1,1,0,0,0,0,0,0},{0,0,1,0,0,0,0,0},{1,0,1,0,0,0,0,0},{0,1,1,0,0,0,0,0},{1,1,1,0,0,0,0,0},{0,0,0,1,0,0,0,0},{1,0,0,1,0,0,0,0},{0,1,0,1,0,0,0,0},{1,1,0,1,0,0,0,0},{0,0,1,1,0,0,0,0},{1,0,1,1,0,0,0,0},{0,1,1,1,0,0,0,0},{1,1,1,1,0,0,0,0},{0,0,0,0,1,0,0,0},{1,0,0,0,1,0,0,0},{0,1,0,0,1,0,0,0},{1,1,0,0,1,0,0,0},{0,0,1,0,1,0,0,0},{1,0,1,0,1,0,0,0},{0,1,1,0,1,0,0,0},{1,1,1,0,1,0,0,0},{0,0,0,1,1,0,0,0},{1,0,0,1,1,0,0,0},{0,1,0,1,1,0,0,0},{1,1,0,1,1,0,0,0},{0,0,1,1,1,0,0,0},{1,0,1,1,1,0,0,0},{0,1,1,1,1,0,0,0},{1,1,1,1,1,0,0,0},{0,0,0,0,0,1,0,0},{1,0,0,0,0,1,0,0},{0,1,0,0,0,1,0,0},{1,1,0,0,0,1,0,0},{0,0,1,0,0,1,0,0},{1,0,1,0,0,1,0,0},{0,1,1,0,0,1,0,0},{1,1,1,0,0,1,0,0},{0,0,0,1,0,1,0,0},{1,0,0,1,0,1,0,0},{0,1,0,1,0,1,0,0},{1,1,0,1,0,1,0,0},{0,0,1,1,0,1,0,0},{1,0,1,1,0,1,0,0},{0,1,1,1,0,1,0,0},{1,1,1,1,0,1,0,0},{0,0,0,0,1,1,0,0},{1,0,0,0,1,1,0,0},{0,1,0,0,1,1,0,0},{1,1,0,0,1,1,0,0},{0,0,1,0,1,1,0,0},{1,0,1,0,1,1,0,0},{0,1,1,0,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,0,1,0,1,1,1},{0,0,1,1,0,1,1,1},{1,0,1,1,0,1,1,1},{0,1,1,1,0,1,1,1},{1,1,1,1,0,1,1,1},{0,0,0,0,1,1,1,1},{1,0,0,0,1,1,1,1},{0,1,0,0,1,1,1,1},{1,1,0,0,1,1,1,1},{0,0,1,0,1,1,1,1},{1,0,1,0,1,1,1,1},{0,1,1,0,1,1,1,1},{1,1,1,0,1,1,1,1},{0,0,0,1,1,1,1,1},{1,0,0,1,1,1,1,1},{0,1,0,1,1,1,1,1},{1,1,0,1,1,1,1,1},{0,0,1,1,1,1,1,1},{1,0,1,1,1,1,1,1},{0,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1}}local function c(d)local e=#d;local f=0;local g=1;for h=1,e do f=f+d[h]*g;g=g*2 end;return f end;local function i(j,e)local k=b[j]local l=b[e]local d={}for h=1,8 do if k[h]~=l[h]then d[h]=1 else d[h]=0 end end;return c(d)end;local function m(n,o)local p=string.format("%o",n)local q={["0"]="000",["1"]="001",["2"]="010",["3"]="011",["4"]="100",["5"]="101",["6"]="110",["7"]="111"}p=string.gsub(p,"(.)",function(r)return q[r]end)p=string.gsub(p,"^0*(.*)$","%1")local s=string.format("%%%ds",o)local t=string.format(s,p)return string.gsub(t," ","0")end;local function u(v,w,n,x)if w=="1"then v[n][x]=2 else v[n][x]=-2 end end;local function y(z)local A;if string.match(z,"^[0-9]+$")then return 1 elseif string.match(z,"^[0-9A-Z $%%*./:+-]+$")then return 2 else return 4 end;assert(false,"never reached")return nil end;local B={{19,16,13,9},{34,28,22,16},{55,44,34,26},{80,64,48,36},{108,86,62,46},{136,108,76,60},{156,124,88,66},{194,154,110,86},{232,182,132,100},{274,216,154,122},{324,254,180,140},{370,290,206,158},{428,334,244,180},{461,365,261,197},{523,415,295,223},{589,453,325,253},{647,507,367,283},{721,563,397,313},{795,627,445,341},{861,669,485,385},{932,714,512,406},{1006,782,568,442},{1094,860,614,464},{1174,914,664,514},{1276,1000,718,538},{1370,1062,754,596},{1468,1128,808,628},{1531,1193,871,661},{1631,1267,911,701},{1735,1373,985,745},{1843,1455,1033,793},{1955,1541,1115,845},{2071,1631,1171,901},{2191,1725,1231,961},{2306,1812,1286,986},{2434,1914,1354,1054},{2566,1992,1426,1096},{2702,2102,1502,1142},{2812,2216,1582,1222},{2956,2334,1666,1276}}local function C(D,A,E)local F=A;if A==4 then F=3 elseif A==8 then F=4 end;assert(F<=4)local G,H,o,I,J;local K={{10,9,8,8},{12,11,16,10},{14,13,16,12}}local L=40;local M=1;for N=1,4 do if E==nil or N>=E then for O=1,#B do H=B[O][N]*8;H=H-4;if O<10 then o=K[1][F]elseif O<27 then o=K[2][F]elseif O<=40 then o=K[3][F]end;I=H-o;if F==1 then J=math.floor(I*3/10)elseif F==2 then J=math.floor(I*2/11)elseif F==3 then J=math.floor(I*1/8)else J=math.floor(I*1/13)end;if J>=D then if O<=L then L=O;M=N end;break end end end end;return L,M end;local function P(z,O,A)local h=A;if A==4 then h=3 elseif A==8 then h=4 end;assert(h<=4)local K={{10,9,8,8},{12,11,16,10},{14,13,16,12}}local o;if O<10 then o=K[1][h]elseif O<27 then o=K[2][h]elseif O<=40 then o=K[3][h]else assert(false,"get_length, version > 40 not supported")end;local D=m(#z,o)return D end;local function Q(z,E,A)local F;if A then assert(false,"not implemented")F=A else F=y(z)end;local O,N;O,N=C(#z,F,E)local R=P(z,O,F)return O,N,m(F,4),F,R end;local S={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,36,-1,-1,-1,37,38,-1,-1,-1,-1,39,40,-1,41,42,43,0,1,2,3,4,5,6,7,8,9,44,-1,-1,-1,-1,-1,-1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,-1,-1,-1,-1,-1}local function T(z)local w=""local U;string.gsub(z,"..?.?",function(q)U=tonumber(q)if#q==3 then w=w..m(U,10)elseif#q==2 then w=w..m(U,7)else w=w..m(U,4)end end)return w end;local function V(z)local w=""local U;local W,X;string.gsub(z,"..?",function(q)if#q==2 then W=S[string.byte(string.sub(q,1,1))]X=S[string.byte(string.sub(q,2,2))]U=W*45+X;w=w..m(U,11)else U=S[string.byte(q)]w=w..m(U,6)end end)return w end;local function Y(z)local t={}string.gsub(z,".",function(n)t[#t+1]=m(string.byte(n),8)end)return table.concat(t)end;local function Z(z,A)if A==1 then return T(z)elseif A==2 then return V(z)elseif A==4 then return Y(z)else assert(false,"not implemented yet")end end;local function _(O,N,a0)local a1,a2;local a3=B[O][N]*8;a1=math.min(4,a3-#a0)if a1>0 then a0=a0 ..string.rep("0",a1)end;if math.fmod(#a0,8)~=0 then a2=8-math.fmod(#a0,8)a0=a0 ..string.rep("0",a2)end;assert(math.fmod(#a0,8)==0)while#a0<a3 do a0=a0 .."11101100"if#a0<a3 then a0=a0 .."00010001"end end;return a0 end;local a4={[0]=0,2,4,8,16,32,64,128,29,58,116,232,205,135,19,38,76,152,45,90,180,117,234,201,143,3,6,12,24,48,96,192,157,39,78,156,37,74,148,53,106,212,181,119,238,193,159,35,70,140,5,10,20,40,80,160,93,186,105,210,185,111,222,161,95,190,97,194,153,47,94,188,101,202,137,15,30,60,120,240,253,231,211,187,107,214,177,127,254,225,223,163,91,182,113,226,217,175,67,134,17,34,68,136,13,26,52,104,208,189,103,206,129,31,62,124,248,237,199,147,59,118,236,197,151,51,102,204,133,23,46,92,184,109,218,169,79,158,33,66,132,21,42,84,168,77,154,41,82,164,85,170,73,146,57,114,228,213,183,115,230,209,191,99,198,145,63,126,252,229,215,179,123,246,241,255,227,219,171,75,150,49,98,196,149,55,110,220,165,87,174,65,130,25,50,100,200,141,7,14,28,56,112,224,221,167,83,166,81,162,89,178,121,242,249,239,195,155,43,86,172,69,138,9,18,36,72,144,61,122,244,245,247,243,251,235,203,139,11,22,44,88,176,125,250,233,207,131,27,54,108,216,173,71,142,1}local a5={[0]=0,255,1,25,2,50,26,198,3,223,51,238,27,104,199,75,4,100,224,14,52,141,239,129,28,193,105,248,200,8,76,113,5,138,101,47,225,36,15,33,53,147,142,218,240,18,130,69,29,181,194,125,106,39,249,185,201,154,9,120,77,228,114,166,6,191,139,98,102,221,48,253,226,152,37,179,16,145,34,136,54,208,148,206,143,150,219,189,241,210,19,92,131,56,70,64,30,66,182,163,195,72,126,110,107,58,40,84,250,133,186,61,202,94,155,159,10,21,121,43,78,212,229,172,115,243,167,87,7,112,192,247,140,128,99,13,103,74,222,237,49,197,254,24,227,165,153,119,38,184,180,124,17,68,146,217,35,32,137,46,55,63,209,91,149,188,207,205,144,135,151,178,220,252,190,97,242,86,211,171,20,42,93,158,132,60,57,83,71,109,65,162,31,45,67,216,183,123,164,118,196,23,73,236,127,12,111,246,108,161,59,82,41,157,85,170,251,96,134,177,187,204,62,90,203,89,95,176,156,169,160,81,11,245,22,235,122,117,44,215,79,174,213,233,230,231,173,232,116,214,244,234,168,80,88,175}local a6={[7]={21,102,238,149,146,229,87,0},[10]={45,32,94,64,70,118,61,46,67,251,0},[13]={78,140,206,218,130,104,106,100,86,100,176,152,74,0},[15]={105,99,5,124,140,237,58,58,51,37,202,91,61,183,8,0},[16]={120,225,194,182,169,147,191,91,3,76,161,102,109,107,104,120,0},[17]={136,163,243,39,150,99,24,147,214,206,123,239,43,78,206,139,43,0},[18]={153,96,98,5,179,252,148,152,187,79,170,118,97,184,94,158,234,215,0},[20]={190,188,212,212,164,156,239,83,225,221,180,202,187,26,163,61,50,79,60,17,0},[22]={231,165,105,160,134,219,80,98,172,8,74,200,53,221,109,14,230,93,242,247,171,210,0},[24]={21,227,96,87,232,117,0,111,218,228,226,192,152,169,180,159,126,251,117,211,48,135,121,229,0},[26]={70,218,145,153,227,48,102,13,142,245,21,161,53,165,28,111,201,145,17,118,182,103,2,158,125,173,0},[28]={123,9,37,242,119,212,195,42,87,245,43,21,201,232,27,205,147,195,190,110,180,108,234,224,104,200,223,168,0},[30]={180,192,40,238,216,251,37,156,130,224,193,226,173,42,125,222,96,239,86,110,48,50,182,179,31,216,152,145,173,41,0}}local function a7(a0)local a8={}local K=string.gsub(a0,"(........)",function(n)a8[#a8+1]=tonumber(n,2)end)return a8 end;function get_generator_polynominal_adjusted(a9,aa)local ab={[0]=0}for h=0,aa-a9-1 do ab[h]=0 end;local ac=a6[a9]for h=1,a9+1 do ab[aa-a9+h-1]=ac[h]end;return ab end;local function ad(K)local ae={}for h=0,#K do ae[h]=a5[K[h]]end;return ae end;local function af(K,ag)local ae={}for h=0,#K do ae[h]=a4[K[h]]end;return ae end;local function ah(a0,a9)local ai;if type(a0)=="string"then ai=a7(a0)elseif type(a0)=="table"then ai=a0 else assert(false,"Unknown type for data: %s",type(a0))end;local ag=#ai;local aa=ag+a9-1;local ab,aj;local ak;local al={}local am,an={},{}for h=1,ag do am[aa-h+1]=ai[h]end;for h=1,aa-ag do am[h]=0 end;am[0]=0;an=ad(am)while aa>=a9 do ab=get_generator_polynominal_adjusted(a9,aa)local ao=an[aa]for h=aa,aa-a9,-1 do if ab[h]+ao>255 then ab[h]=math.fmod(ab[h]+ao,255)else ab[h]=ab[h]+ao end end;for h=aa-a9-1,0,-1 do ab[h]=0 end;al=af(ab)am=af(an)aj={}for h=aa,0,-1 do aj[h]=i(al[h],am[h])end;ak=aa;for h=ak,0,-1 do if h<a9 then break end;if aj[h]==0 then aj[h]=nil;aa=aa-1 else break end end;am=aj;an=ad(am)end;local t={}for h=#am,0,-1 do t[#t+1]=am[h]end;return t end;local ap={{{1,{26,19,2}},{1,{26,16,4}},{1,{26,13,6}},{1,{26,9,8}}},{{1,{44,34,4}},{1,{44,28,8}},{1,{44,22,11}},{1,{44,16,14}}},{{1,{70,55,7}},{1,{70,44,13}},{2,{35,17,9}},{2,{35,13,11}}},{{1,{100,80,10}},{2,{50,32,9}},{2,{50,24,13}},{4,{25,9,8}}},{{1,{134,108,13}},{2,{67,43,12}},{2,{33,15,9},2,{34,16,9}},{2,{33,11,11},2,{34,12,11}}},{{2,{86,68,9}},{4,{43,27,8}},{4,{43,19,12}},{4,{43,15,14}}},{{2,{98,78,10}},{4,{49,31,9}},{2,{32,14,9},4,{33,15,9}},{4,{39,13,13},1,{40,14,13}}},{{2,{121,97,12}},{2,{60,38,11},2,{61,39,11}},{4,{40,18,11},2,{41,19,11}},{4,{40,14,13},2,{41,15,13}}},{{2,{146,116,15}},{3,{58,36,11},2,{59,37,11}},{4,{36,16,10},4,{37,17,10}},{4,{36,12,12},4,{37,13,12}}},{{2,{86,68,9},2,{87,69,9}},{4,{69,43,13},1,{70,44,13}},{6,{43,19,12},2,{44,20,12}},{6,{43,15,14},2,{44,16,14}}},{{4,{101,81,10}},{1,{80,50,15},4,{81,51,15}},{4,{50,22,14},4,{51,23,14}},{3,{36,12,12},8,{37,13,12}}},{{2,{116,92,12},2,{117,93,12}},{6,{58,36,11},2,{59,37,11}},{4,{46,20,13},6,{47,21,13}},{7,{42,14,14},4,{43,15,14}}},{{4,{133,107,13}},{8,{59,37,11},1,{60,38,11}},{8,{44,20,12},4,{45,21,12}},{12,{33,11,11},4,{34,12,11}}},{{3,{145,115,15},1,{146,116,15}},{4,{64,40,12},5,{65,41,12}},{11,{36,16,10},5,{37,17,10}},{11,{36,12,12},5,{37,13,12}}},{{5,{109,87,11},1,{110,88,11}},{5,{65,41,12},5,{66,42,12}},{5,{54,24,15},7,{55,25,15}},{11,{36,12,12},7,{37,13,12}}},{{5,{122,98,12},1,{123,99,12}},{7,{73,45,14},3,{74,46,14}},{15,{43,19,12},2,{44,20,12}},{3,{45,15,15},13,{46,16,15}}},{{1,{135,107,14},5,{136,108,14}},{10,{74,46,14},1,{75,47,14}},{1,{50,22,14},15,{51,23,14}},{2,{42,14,14},17,{43,15,14}}},{{5,{150,120,15},1,{151,121,15}},{9,{69,43,13},4,{70,44,13}},{17,{50,22,14},1,{51,23,14}},{2,{42,14,14},19,{43,15,14}}},{{3,{141,113,14},4,{142,114,14}},{3,{70,44,13},11,{71,45,13}},{17,{47,21,13},4,{48,22,13}},{9,{39,13,13},16,{40,14,13}}},{{3,{135,107,14},5,{136,108,14}},{3,{67,41,13},13,{68,42,13}},{15,{54,24,15},5,{55,25,15}},{15,{43,15,14},10,{44,16,14}}},{{4,{144,116,14},4,{145,117,14}},{17,{68,42,13}},{17,{50,22,14},6,{51,23,14}},{19,{46,16,15},6,{47,17,15}}},{{2,{139,111,14},7,{140,112,14}},{17,{74,46,14}},{7,{54,24,15},16,{55,25,15}},{34,{37,13,12}}},{{4,{151,121,15},5,{152,122,15}},{4,{75,47,14},14,{76,48,14}},{11,{54,24,15},14,{55,25,15}},{16,{45,15,15},14,{46,16,15}}},{{6,{147,117,15},4,{148,118,15}},{6,{73,45,14},14,{74,46,14}},{11,{54,24,15},16,{55,25,15}},{30,{46,16,15},2,{47,17,15}}},{{8,{132,106,13},4,{133,107,13}},{8,{75,47,14},13,{76,48,14}},{7,{54,24,15},22,{55,25,15}},{22,{45,15,15},13,{46,16,15}}},{{10,{142,114,14},2,{143,115,14}},{19,{74,46,14},4,{75,47,14}},{28,{50,22,14},6,{51,23,14}},{33,{46,16,15},4,{47,17,15}}},{{8,{152,122,15},4,{153,123,15}},{22,{73,45,14},3,{74,46,14}},{8,{53,23,15},26,{54,24,15}},{12,{45,15,15},28,{46,16,15}}},{{3,{147,117,15},10,{148,118,15}},{3,{73,45,14},23,{74,46,14}},{4,{54,24,15},31,{55,25,15}},{11,{45,15,15},31,{46,16,15}}},{{7,{146,116,15},7,{147,117,15}},{21,{73,45,14},7,{74,46,14}},{1,{53,23,15},37,{54,24,15}},{19,{45,15,15},26,{46,16,15}}},{{5,{145,115,15},10,{146,116,15}},{19,{75,47,14},10,{76,48,14}},{15,{54,24,15},25,{55,25,15}},{23,{45,15,15},25,{46,16,15}}},{{13,{145,115,15},3,{146,116,15}},{2,{74,46,14},29,{75,47,14}},{42,{54,24,15},1,{55,25,15}},{23,{45,15,15},28,{46,16,15}}},{{17,{145,115,15}},{10,{74,46,14},23,{75,47,14}},{10,{54,24,15},35,{55,25,15}},{19,{45,15,15},35,{46,16,15}}},{{17,{145,115,15},1,{146,116,15}},{14,{74,46,14},21,{75,47,14}},{29,{54,24,15},19,{55,25,15}},{11,{45,15,15},46,{46,16,15}}},{{13,{145,115,15},6,{146,116,15}},{14,{74,46,14},23,{75,47,14}},{44,{54,24,15},7,{55,25,15}},{59,{46,16,15},1,{47,17,15}}},{{12,{151,121,15},7,{152,122,15}},{12,{75,47,14},26,{76,48,14}},{39,{54,24,15},14,{55,25,15}},{22,{45,15,15},41,{46,16,15}}},{{6,{151,121,15},14,{152,122,15}},{6,{75,47,14},34,{76,48,14}},{46,{54,24,15},10,{55,25,15}},{2,{45,15,15},64,{46,16,15}}},{{17,{152,122,15},4,{153,123,15}},{29,{74,46,14},14,{75,47,14}},{49,{54,24,15},10,{55,25,15}},{24,{45,15,15},46,{46,16,15}}},{{4,{152,122,15},18,{153,123,15}},{13,{74,46,14},32,{75,47,14}},{48,{54,24,15},14,{55,25,15}},{42,{45,15,15},32,{46,16,15}}},{{20,{147,117,15},4,{148,118,15}},{40,{75,47,14},7,{76,48,14}},{43,{54,24,15},22,{55,25,15}},{10,{45,15,15},67,{46,16,15}}},{{19,{148,118,15},6,{149,119,15}},{18,{75,47,14},31,{76,48,14}},{34,{54,24,15},34,{55,25,15}},{20,{45,15,15},61,{46,16,15}}}}local aq={0,7,7,7,7,7,0,0,0,0,0,0,0,3,3,3,3,3,3,3,4,4,4,4,4,4,4,3,3,3,3,3,3,3,0,0,0,0,0,0}local function ar(O,N,a0)if type(a0)=="table"then local aj=""for h=1,#a0 do aj=aj..m(a0[h],8)end;a0=aj end;local as=ap[O][N]local at,au;local av={}local ap={}local aw=1;local ax=0;local ay=0;for h=1,#as/2 do for az=1,as[2*h-1]do at=as[2*h][2]au=as[2*h][1]-as[2*h][2]ay=ay+au*8;av[#av+1]=string.sub(a0,ax*8+1,(ax+at)*8)tmp_tab=ah(av[#av],au)tmp_str=""for n=1,#tmp_tab do tmp_str=tmp_str..m(tmp_tab[n],8)end;ap[#ap+1]=tmp_str;ax=ax+at;aw=aw+1 end end;local aA=""ax=1;repeat for h=1,#av do os.sleep(0)if ax<#av[h]then aA=aA..string.sub(av[h],ax,ax+7)end end;ax=ax+8 until#aA==#a0;local aB=""ax=1;repeat for h=1,#ap do os.sleep(0)if ax<#ap[h]then aB=aB..string.sub(ap[h],ax,ax+7)end end;ax=ax+8 until#aB==ay;return aA..aB end;local function aC(aD)local size=#aD;for h=1,8 do for az=1,8 do aD[h][az]=-2;aD[size-8+h][az]=-2;aD[h][size-8+az]=-2 end end;for h=1,7 do aD[1][h]=2;aD[7][h]=2;aD[h][1]=2;aD[h][7]=2;aD[size][h]=2;aD[size-6][h]=2;aD[size-h+1][1]=2;aD[size-h+1][7]=2;aD[1][size-h+1]=2;aD[7][size-h+1]=2;aD[h][size-6]=2;aD[h][size]=2 end;for h=1,3 do for az=1,3 do aD[2+az][h+2]=2;aD[size-az-1][h+2]=2;aD[2+az][size-h-1]=2 end end end;local function aE(aD)local aF,aG;aF=7;aG=9;for h=aG,#aD-8 do if math.fmod(h,2)==1 then aD[h][aF]=2 else aD[h][aF]=-2 end end;for h=aG,#aD-8 do if math.fmod(h,2)==1 then aD[aF][h]=2 else aD[aF][h]=-2 end end end;local aH={{},{6,18},{6,22},{6,26},{6,30},{6,34},{6,22,38},{6,24,42},{6,26,46},{6,28,50},{6,30,54},{6,32,58},{6,34,62},{6,26,46,66},{6,26,48,70},{6,26,50,74},{6,30,54,78},{6,30,56,82},{6,30,58,86},{6,34,62,90},{6,28,50,72,94},{6,26,50,74,98},{6,30,54,78,102},{6,28,54,80,106},{6,32,58,84,110},{6,30,58,86,114},{6,34,62,90,118},{6,26,50,74,98,122},{6,30,54,78,102,126},{6,26,52,78,104,130},{6,30,56,82,108,134},{6,34,60,86,112,138},{6,30,58,86,114,142},{6,34,62,90,118,146},{6,30,54,78,102,126,150},{6,24,50,76,102,128,154},{6,28,54,80,106,132,158},{6,32,58,84,110,136,162},{6,26,54,82,110,138,166},{6,30,58,86,114,142,170}}local function aI(aD)local O=(#aD-17)/4;local aJ=aH[O]local aK,aL;for n=1,#aJ do for x=1,#aJ do if not(n==1 and x==1 or n==#aJ and x==1 or n==1 and x==#aJ)then aK=aJ[n]+1;aL=aJ[x]+1;aD[aK][aL]=2;aD[aK+1][aL]=-2;aD[aK-1][aL]=-2;aD[aK+2][aL]=2;aD[aK-2][aL]=2;aD[aK][aL-2]=2;aD[aK+1][aL-2]=2;aD[aK-1][aL-2]=2;aD[aK+2][aL-2]=2;aD[aK-2][aL-2]=2;aD[aK][aL+2]=2;aD[aK+1][aL+2]=2;aD[aK-1][aL+2]=2;aD[aK+2][aL+2]=2;aD[aK-2][aL+2]=2;aD[aK][aL-1]=-2;aD[aK+1][aL-1]=-2;aD[aK-1][aL-1]=-2;aD[aK+2][aL-1]=2;aD[aK-2][aL-1]=2;aD[aK][aL+1]=-2;aD[aK+1][aL+1]=-2;aD[aK-1][aL+1]=-2;aD[aK+2][aL+1]=2;aD[aK-2][aL+1]=2 end end end end;local aM={{[-1]="111111111111111",[0]="111011111000100","111001011110011","111110110101010","111100010011101","110011000101111","110001100011000","110110001000001","110100101110110"},{[-1]="111111111111111",[0]="101010000010010","101000100100101","101111001111100","101101101001011","100010111111001","100000011001110","100111110010111","100101010100000"},{[-1]="111111111111111",[0]="011010101011111","011000001101000","011111100110001","011101000000110","010010010110100","010000110000011","010111011011010","010101111101101"},{[-1]="111111111111111",[0]="001011010001001","001001110111110","001110011100111","001100111010000","000011101100010","000001001010101","000110100001100","000100000111011"}}local function aN(v,N,aO)local aP=aM[N][aO]local aQ;for h=1,7 do aQ=string.sub(aP,h,h)u(v,aQ,9,#v-h+1)end;for h=8,9 do aQ=string.sub(aP,h,h)u(v,aQ,9,17-h)end;for h=10,15 do aQ=string.sub(aP,h,h)u(v,aQ,9,16-h)end;for h=1,6 do aQ=string.sub(aP,h,h)u(v,aQ,h,9)end;aQ=string.sub(aP,7,7)u(v,aQ,8,9)for h=8,15 do aQ=string.sub(aP,h,h)u(v,aQ,#v-15+h,9)end end;local aR={"001010010011111000","000111101101000100","100110010101100100","011001011001010100","011011111101110100","001000110111001100","111000100001101100","010110000011011100","000101001001111100","000111101101000010","010111010001100010","111010000101010010","001001100101110010","011001011001001010","011000001011101010","100100110001011010","000110111111111010","001000110111000110","000100001111100110","110101011111010110","000001110001110110","010110000011001110","001111110011101110","101011101011011110","000000101001111110","101010111001000001","000001111011100001","010111010001010001","011111001111110001","110100001101001001","001110100001101001","001001100101011001","010000010101111001","100101100011000101"}local function aS(v,O)if O<7 then return end;local size=#v;local w=aR[O-6]local n,x,aQ;local aT,aU;aT=#v-10;aU=1;for h=1,#w do aQ=string.sub(w,h,h)n=aT+math.fmod(h-1,3)x=aU+math.floor((h-1)/3)u(v,aQ,n,x)end;aT=1;aU=#v-10;for h=1,#w do aQ=string.sub(w,h,h)n=aT+math.floor((h-1)/3)x=aU+math.fmod(h-1,3)u(v,aQ,n,x)end end;local function aV(O,N,aO)local size;local aD={}size=O*4+17;for h=1,size do aD[h]={}for az=1,size do aD[h][az]=0 end end;aC(aD)aE(aD)aS(aD,O)aD[9][size-7]=2;aI(aD)aN(aD,N,aO)return aD end;local function aW(aO,n,x,aX)n=n-1;x=x-1;local aY=false;if aO==-1 then elseif aO==0 then if math.fmod(n+x,2)==0 then aY=true end elseif aO==1 then if math.fmod(x,2)==0 then aY=true end elseif aO==2 then if math.fmod(n,3)==0 then aY=true end elseif aO==3 then if math.fmod(n+x,3)==0 then aY=true end elseif aO==4 then if math.fmod(math.floor(x/2)+math.floor(n/3),2)==0 then aY=true end elseif aO==5 then if math.fmod(n*x,2)+math.fmod(n*x,3)==0 then aY=true end elseif aO==6 then if math.fmod(math.fmod(n*x,2)+math.fmod(n*x,3),2)==0 then aY=true end elseif aO==7 then if math.fmod(math.fmod(n*x,3)+math.fmod(n+x,2),2)==0 then aY=true end else assert(false,"This can't happen (mask must be <= 7)")end;if aY then return 1-2*tonumber(aX)else return-1+2*tonumber(aX)end end;function get_next_free_positions(v,n,x,aZ,a_)local t={}local aw=1;local A="right"while aw<=#a_ do if A=="right"and v[n][x]==0 then t[#t+1]={n,x}A="left"aw=aw+1 elseif A=="left"and v[n-1][x]==0 then t[#t+1]={n-1,x}A="right"aw=aw+1;if aZ=="up"then x=x-1 else x=x+1 end elseif A=="right"and v[n-1][x]==0 then t[#t+1]={n-1,x}aw=aw+1;if aZ=="up"then x=x-1 else x=x+1 end else if aZ=="up"then x=x-1 else x=x+1 end end;if x<1 or x>#v then n=n-2;if n==7 then n=6 end;if aZ=="up"then aZ="down"x=1 else aZ="up"x=#v end end end;return t,n,x,aZ end;local function b0(v,a0,aO)size=#v;local n,x,b1;local b2,b3,j;local aZ="up"local b4=0;n,x=size,size;string.gsub(a0,".?.?.?.?.?.?.?.?",function(a_)b4=b4+1;b1,n,x,aZ=get_next_free_positions(v,n,x,aZ,a_,aO)for h=1,#a_ do b2=b1[h][1]b3=b1[h][2]j=aW(aO,b2,b3,string.sub(a_,h,h))if debugging then v[b2][b3]=j*(h+10)else v[b2][b3]=j end end end)end;local function b5(v)local b6,b7,b8,b9=0,0,0,0;local size=#v;local ba=0;local bb;local bc;local bd;for n=1,size do bd=0;bb=nil;for x=1,size do if v[n][x]>0 then ba=ba+1;bc=false else bc=true end;bc=v[n][x]<0;if bb==bc then bd=bd+1 else if bd>=5 then b6=b6+bd-2 end;bd=1 end;bb=bc end;if bd>=5 then b6=b6+bd-2 end end;for x=1,size do bd=0;bb=nil;for n=1,size do bc=v[n][x]<0;if bb==bc then bd=bd+1 else if bd>=5 then b6=b6+bd-2 end;bd=1 end;bb=bc end;if bd>=5 then b6=b6+bd-2 end end;for n=1,size do for x=1,size do if x<size-1 and n<size-1 and(v[n][x]<0 and v[n+1][x]<0 and v[n][x+1]<0 and v[n+1][x+1]<0 or v[n][x]>0 and v[n+1][x]>0 and v[n][x+1]>0 and v[n+1][x+1]>0)then b7=b7+3 end;if x+6<size and v[n][x]>0 and v[n][x+1]<0 and v[n][x+2]>0 and v[n][x+3]>0 and v[n][x+4]>0 and v[n][x+5]<0 and v[n][x+6]>0 and(x+10<size and v[n][x+7]<0 and v[n][x+8]<0 and v[n][x+9]<0 and v[n][x+10]<0 or x-4>=1 and v[n][x-1]<0 and v[n][x-2]<0 and v[n][x-3]<0 and v[n][x-4]<0)then b8=b8+40 end;if n+6<=size and v[n][x]>0 and v[n+1][x]<0 and v[n+2][x]>0 and v[n+3][x]>0 and v[n+4][x]>0 and v[n+5][x]<0 and v[n+6][x]>0 and(n+10<=size and v[n+7][x]<0 and v[n+8][x]<0 and v[n+9][x]<0 and v[n+10][x]<0 or n-4>=1 and v[n-1][x]<0 and v[n-2][x]<0 and v[n-3][x]<0 and v[n-4][x]<0)then b8=b8+40 end end end;local be=ba/(size*size)b9=math.floor(math.abs(be*100-50))*2;return b6+b7+b8+b9 end;local function bf(O,N,a0,aO)local K=aV(O,N,aO)b0(K,a0,aO)local bg=b5(K)return K,bg end;local function bh(O,N,a0)local K,bg;local bi,bj;bi,bj=bf(O,N,a0,0)for h=1,7 do K,bg=bf(O,N,a0,h)if bg<bj then bi=K;bj=bg end end;return bi end;local function bk(z,N,A)local aA,O,N,bl,A,bm;O,N,bl,A,bm=Q(z)bl=bl..bm;bl=bl..Z(z,A)bl=_(O,N,bl)aA=ar(O,N,bl)if math.fmod(#aA,8)~=0 then return false,string.format("Arranged data %% 8 != 0: data length = %d, mod 8 = %d",#aA,math.fmod(#aA,8))end;aA=aA..string.rep("0",aq[O])local K=bh(O,N,aA)return true,K end;local function bn(K)local bo={}for h=1,#K+2 do bo[h]={}end;for h=1,#K+2 do bo[h][1]=0;bo[1][h]=0;bo[h][#K+2]=0;bo[#K+2][h]=0 end;for x=1,#K do for n=1,#K do if K[n][x]>0 then bo[x+1][n+1]=1 else bo[x+1][n+1]=0 end end end;return bo end;function a.encode(bp)local bo;local bq,br=bk(bp)if not bq then print(br)else bo=bn(br)end;return bo end;return a
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement