2006-12-06 09:00:00 UTC

# The ultimate end

Status: Failed
Results:

Basis for: EEEEEEENDDDD (diff)

Code
```function solution = solver(n) %B(idx)=idxi;
S=0; %solution(nn, c2-1) = s2 - prev;
%end
if n==10 %for desp = 0:2
solution = zeros(n); %s(6,27)=a;    s(6,30)=a;    s( 7,24 )=80;    s( 8,24 )=a;
%end
sol=ones(n).*-1; %end
%if  rB(i)>0
rT=-1.*ones(1,n); %sR(n)=0;
cT=-1.*ones(1,n); %
sT=-1.*ones(1,n); %if(ri==0 && ci==0)
%s(9,31)=9;    s(10,1)=23;    s(10,24)=27;    s(10,27)=8;
rL=-1.*ones(1,n); %rB(-cR(i))=-i;
%[tmp1,tmp2,s] = mb(nn+1,0,0,rot);
cL=-1.*ones(1,n); %if ~r
sL=-1.*ones(1,n); %if(r==0)
%if rR(i)==-1
rB=-1.*ones(1,n); %L=~(~V&B>0);
cB=-1.*ones(1,n); %cL=-1.*ones(1,n);
sB=-1.*ones(1,n); %while(~(r==-1 && c==0))
rR=-1.*ones(1,n); %end
cR=-1.*ones(1,n); %if (n == 18)
%if (n == 60)
sR=-1.*ones(1,n); %couu = couu + sn;
%end
do1T=1; %if  cR(i)<0;
doNT=1; %tempS=0;
%sB(1)=0;
bl=0; %end
%rR(n)=n;
AAA=0; %
%for c = 1:n
for i=[2:n-1 1 n] %dum=0;
if rT(i)==-1 && ((i~=1 && i~=n) || (i==1 && do1T) || (i==n && doNT)) %if (rn+cn2) == 0
bl=bl+1; %solution(1,1) = max(0,solution(1,1));
%
[rT(i),cT(i),sT(i)] = beam(0,i); %[r,c,s] = mb(nn,0,0,rot);
%if  rB(i)>0
if rT(i)==0 && cT(i)>0  %
rT(cT(i))=0; %solution=s;
cT(cT(i))=i; %sol(1,2)=sT(1);sol(1,1)=0;
sT(cT(i))=sT(i); %idxi=rc2idx(ri,ci);
bl=bl-1; %[r,c,s] = mb(1,0,0,rot);
%else
end %if r&&c
%rc=r+c;
if rT(i)==0 && cT(i)<0 %end
rB(-cT(i))=0; %end
%rr = 0;
cB(-cT(i))=i; %if B==1
sB(-cT(i))=sT(i); %sT(cT(i))=sT(i);
bl=bl-1; %[r,c,s] = mb(0,tc,0,rot);
%function solution = solver(n)
if i==2 && sT(i)==0 %[r2,c2,s2] = mb(0,c+2,0,rot);
rB(1)=0; %if cn-2 < -n
cB(1)=1; %
sB(1)=0; %solution(1,1:min(n,c+2)) = max(0,solution(1,1:min(n,c+2)));
rT(1)=0; %end
cT(1)=-1; %end
sT(1)=0; %end
%else
do1T=0; %end
%V(L)=-1;
end %end
%[rB2(i5),cB2(i5),sB2(i5)] = beam2(0,-i5,n);
if i==n-1 && sT(i)==0 %solution(nn,c+1) = s-solution(nn,sc-1);
%cL(rB(i))=-i;
rB(n)=0; %sol(tempR+1:end,tempC)=0;sol(tempR,1:tempC-1)=0;
%if(r2)
cB(n)=n; %s( 16,23 )=a;    s( 18,2 )=a;    s( 18,6 )=a;    s( 19,23 )=a;
sB(n)=0; %rR(1)=1;
%j = 2;
rT(n)=0; %end
%s( 38,16 )=a;    s( 39,4 )=77;    s( 39,32 )=a;
cT(n)=-1.*n; %sol(tempR,tempC)=0;
sT(n)=0; %sol(tempR,tempC)=0;
%if  sol(tempR,tempC)>99
doNT=0; %ru(-cn+1) = sn;
end %end
%for rot = [1 6 4 2 7 5 0]
end %r = r + ir(d);
if rT(i)>0 && cT(i)==0  %end
bl=bl-1; %end
rL(rT(i))=0; %sT(cB(i))=sB(i);
%s( 27,9 )=a;    s( 27,15 )=a;    s( 28,16 )=a;    s( 29,6 )=a;
cL(rT(i))=i; %sol(1:tempR-1,tempC)=0;
sL(rT(i))=sT(i); %end
%end
end %a = rot90(ai,r);
if rT(i)<0 && cT(i)==0 %if B==1
bl=bl-1; %end
rR(-rT(i))=0; %return
%a = rot90(ai,r);
cR(-rT(i))=i; %rB=-1.*ones(1,n);
%bl=bl+1;
sR(-rT(i))=sT(i); %[rT2(i5),cT2(i5),sT2(i5)] = beam2(0,i5,n);
%elseif r==rr && c==cc && ss
end %rB(-cB(i))=0;
%B(L)=-1;
end %end
%AAA=0;
if bl>=0.39*n %r = rem(r-1,n+1);
%prev = s2;
AAA=1; %cT(cL(i))=0;
break; %if rT(i)==0 && cT(i)<0
end %end
%elseif rT(i)<0;
end %r=(c>0)+(c<0)*n;
%ru(-cn+1) = sn;
if AAA<0.4 %end
%cR(-rL(i))=0;
do1L=1; %rT(cL(i))=i;
doNL=1; %cB(n)=n;
%sol = lrow(n-nn+1,sol2,mod(rot+2,4)+4*(rot>=4));
for i=[2:n-1 1 n] %if sL(i)==0 && rL(i)==-i && cT(i)==0;
%varargout = {r,c,ch};
if rL(i)==-1 && ((i~=1 && i~=n) || (i==1 && do1L) || (i==n && doNL)) %sol(tempR,tempC)=0;
[rL(i),cL(i),sL(i)] = beam(i,0); %end
if rL(i)==0 && cL(i)>0 %s(1,16)=17;    s(1,23)=9;    s(1,24)=9;    s(1,31)=1;
rT(cL(i))=i; %
cT(cL(i))=0; %[r2,c2,s2] = mb(0,c+2,0,rot);
%return
sT(cL(i))=sL(i); %rB(n)=0;
end %else
if rL(i)==0 && cL(i)<0 %prev = ro(c)-prev;
%end
rB(-cL(i))=i; %if(r>=4)
cB(-cL(i))=0; %end
%
sB(-cL(i))=sL(i); %[rR2(i5),cR2(i5),sR2(i5)] = beam2(-i5,0,n);
%idx=rc2idx(r,c);
end %
if rL(i)>0 && cL(i)==0  %elseif(ri==0)
rL(rL(i))=i; %solution = max(0,solution);
cL(rL(i))=0; %rR(-rL(i))=i;
sL(rL(i))=sL(i); %solution(nn,n)=s2;
%end
end %end
%end
if rL(i)<0 && cL(i)==0 %do1T=1;
%sol = solution;
rR(-rL(i))=i; %return;
cR(-rL(i))=0; %[r3,c3,s3] = mb(0,2,0,rot);
%end
sR(-rL(i))=sL(i); %fnd=1;
if i==2 && sL(i)==0 %end
rR(1)=1; %end
cR(1)=0; %[tmp1,tmp2,s] = mb(j,0,0,rot);
sR(1)=0; %[rR2(i5),cR2(i5),sR2(i5)] = beam2(-i5,0,n);
rL(1)=-1; %if (rn+cn2) == 0
cL(1)=0; %if(r==0)
sL(1)=0; %s=zeros(n);
%solution(nn,sc) = s-solution(nn,c-1);
do1L=0; %solution(nn,sc) = s;
%sR(1)=0;
end %else
if i==n-1 && sL(i)==0 %c=(rr>0)+(rr<0)*n;
%if i==2 && sL(i)==0
rR(n)=n; %sol(tempR,tempC+1:end)=0;sol(tempR+1:end,tempC)=0;
cR(n)=0; %end
%sol(1:tempR-1,tempC)=0;
sR(n)=0; %end
%couu = -1;
rL(n)=-n; %sol = lrow(n-nn+1,sol2,mod(rot+2,4)+4*(rot>=4));
%sol(1:tempR-1,tempC)=0;
cL(n)=0; %rc=idx-d*n;
%if n==10
sL(n)=0; %end
doNL=0; %end
%sR(-rT(i))=sT(i);
end %ro = zeros(n,1);
%
%if  cR(i)<0;
%end
%rR(-rB(i))=0;
end %if(~fnd)
end %
%end
if rB(i)==-1 %r=(cc>0)+(cc<0)*n;
[rB(i),cB(i),sB(i)] = beam(0,-i); %[rL2(i5),cL2(i5),sL2(i5)] = beam2(i5,0,n);
%mb(0,c+1,1,rot);
if rB(i)==0 && cB(i)>0 %elseif rT(i)<0;
rT(cB(i))=0; %vi=V(idx);
cT(cB(i))=-i; %if(ri==0 && ci==0)
sT(cB(i))=sB(i); %end
end %s( 30,2 )=a;    s( 30,9 )=a;    s( 30,10 )=a;    s( 30,29 )=a;
if rB(i)==0 && cB(i)<0  %bl=bl-1;
rB(-cB(i))=0; %cL(rB(i))=-i;
%else
cB(-cB(i))=-i; %end
%solution(nn,c+1) = s;
sB(-cB(i))=sB(i); %cc = sign(ci)*(n-abs(ci)+1);
end %[rn,cn2,sn] = mb(0,cn-2,0,rot);
if rB(i)>0 && cB(i)==0 %if rB(1)==0 && cB(1)==-1
%
rL(rB(i))=0; %else
cL(rB(i))=-i; %end
%j = j+1;
sL(rB(i))=sB(i); %solution(r,max(1,min(n,abs(cc)+(-1:1))))=max(0,solution(r,max(1,min(n,abs(cc)+(-1:1)))));
%s(24,20)=27;    s(24,26)=45;    s(26,28)=45;    s(29,40)=45;
end %sol = ra(sol,mod(rot+2,4)+4*(rot>=4));
if rB(i)<0 && cB(i)==0 %B(idxi)=idx;
%nn = nn-1;
rR(-rB(i))=0; %c = rem(c-1,n+1);
cR(-rB(i))=-i; %cR(-rR(i))=0;
%end
sR(-rB(i))=sB(i); %if(nn==n-1)
%sR(-rR(i))=sR(i);
end %if(rot<=0)
%end
end %s( 16,23 )=a;    s( 18,2 )=a;    s( 18,6 )=a;    s( 19,23 )=a;
if rR(i)==-1 %if ru(c) == -1
%end
[rR(i),cR(i),sR(i)] = beam(-i,0); %if rB(i)>0 && cB(i)==0
if rR(i)==0 && cR(i)>0  %end
%B=0;
rT(cR(i))=-i; %end
%cR=-1.*ones(1,n);
cT(cR(i))=0; %s( 31,6 )=a;    s( 33,24 )=a;    s( 34,6 )=a;    s( 34,18 )=a;
%end
sT(cR(i))=sR(i); %if (n == 40)
%
end %s( 13,32 )=a;    s( 13,33 )=a;    s( 14,39 )=a;    s( 15,9 )=a;
%if(r==0)
if rR(i)==0 && cR(i)<0  %couo = 0;
%sol(n,i+1)=sB(i);sol(n,i)=0;sol(n,i+2)=0;
rB(-cR(i))=-i; %else
cB(-cR(i))=0; %if(r==0)
sB(-cR(i))=sR(i); %end
end %if rR(i)==0 && cR(i)>0
%solution = zeros(n);
if rR(i)>0 && cR(i)==0 %sol(tempR,1:tempC-1)=0;sol(1:tempR-1,tempC)=0;
rL(rR(i))=-i; %if ru(c) == -1
cL(rR(i))=0; %cn = cn2;
sL(rR(i))=sR(i); %if rR(i)==-i  && sR(i+1)==0 && rR(i+1)==0 && cR(i+1)==0 && sR(i+2)==sR(i)
end %end
%break;
if rR(i)<0 && cR(i)==0  %s(30,42)=35;s(37,31)=35;s(39,37)=35;s(36,43)=35;s(36,42)=35;
rR(-rR(i))=-i; %end
cR(-rR(i))=0; %sol(tempR,tempC)=tempS;B=1;
sR(-rR(i))=sR(i); %
%elseif ~c
end %rT(cB(i))=0;
end %end
end %if(nn<n)
%end
if rT(1)==0 && cT(1)==1 %end
sol(1,2)=sT(1);sol(1,1)=0; %rr = -ri;
%s( 27,9 )=a;    s( 27,15 )=a;    s( 28,16 )=a;    s( 29,6 )=a;
end %end
if rL(1)==1 && cL(1)==0 %solution(1,1) = max(s2,s3);
%cB(-cL(i))=0;
sol(2,1)=sL(1);sol(1,1)=0; %end
%if couu == -1
end %a=fliplr(rot90(ai,-r));
%rL(rT(i))=0;
if rB(1)==0 && cB(1)==-1 %rR(-rR(i))=-i;
sol(n,2)=sT(1);sol(n,1)=0; %sol(1:tempR-1,tempC)=0;
%s(6,30)=14;    s(6,34)=11;    s(7,4)=8;    s(7,10)=24;
end %solution(r+sign(c),abs(c))=max(0,solution(r+sign(c),abs(c)));
%if sL(i)==0 && rL(i)==-i && cT(i)==0;
if rR(1)==-1 && cR(1)==0 %cL(1)=0;
sol(2,n)=sT(1);sol(1,n)=0; %nn = nn-1;
end %sL=-1.*ones(1,n);
%V(L)=-1;
if rT(n)==0 && cT(n)==n %if(r==0)
%end
sol(1,n-1)=sT(n);sol(1,n)=0; %idxi=rc2idx(ri,ci);
end %else
%cL=-1.*ones(1,n);
if rL(n)==n && cL(n)==0 %sR(1)=0;
%global A turns charge newd ir ic
sol(n-1,1)=sL(n);sol(n,1)=0; %end
end %rT(cB(i))=0;
if rB(n)==0 && cB(n)==-n %if (n == 54)
sol(n,n-1)=sT(n);sol(n,n)=0; %elseif(~r)
%couo = -1;
end %cc = 0;
if rR(n)==-n && cR(n)==0 %solution(j+1,c+1) = s;
sol(n-1,n)=sT(n);sol(n,n)=0; %sol(tempR,tempC)=0;
end %if couu == -1
%varargout = {0,0,0};
%if rL(i)==0 && cL(i)<0
for i=1:n %return
%if tempS>0
if sT(i)==0 && rT(i)==0 && cT(i)==-i; %if couo <= couu
sol(:,i)=0;if i>1; sol(:,i-1)=0;end;if i<n; sol(:,i+1)=0;end %if r2 == 2 && c3==2
%else
end %[ri,ci,ss] = mb(-r,0,i,rot-4,dum);
if sL(i)==0 && rL(i)==-i && cT(i)==0; %end
%end
sol(i,:)=0;if i>1; sol(i-1,:)=0;end;if i<n; sol(i+1,:)=0;end %end
%if sc==n
end %[r,c,s] = mb(1,0,0,rot);
if sB(i)==0 && rB(i)==0 && cB(i)==i; %sT(1)=0;
sol(:,i)=0;if i>1; sol(:,i-1)=0;end;if i<n; sol(:,i+1)=0;end %rB(-cL(i))=i;
end %
if sR(i)==0 && rR(i)==i && cR(i)==0; %if(~r)
sol(i,:)=0;if i>1; sol(i-1,:)=0;end;if i<n; sol(i+1,:)=0;end %if r&&c
%c = c+1 + ((n+1)*(d==4));
end %for i=2:n-2
%rR=-1.*ones(1,n);
end %end
%cc = 0;
%3 4 1 2];
%charge(C|B) = 0;
for i=2:n-2 %sol(n,n-1)=sT(n);sol(n,n)=0;
if rL(i)==i  && sL(i+1)==0 && rL(i+1)==0 && cL(i+1)==0 && sL(i+2)==sL(i) %if(rot<=0)
%sol(tempR+1:end,tempC)=0;sol(tempR,tempC+1:end)=0;
sol(i+1,1)=sL(i); sol(i,1)=0;sol(i+2,1)=0; %while(c+2<=n && r~=-(nn-1))
end %function varargout = beam2(r,c,n,beamIntensity)
%B = conv2(A,[0 0 0;0 1 0;0 0 0]);
if rR(i)==-i  && sR(i+1)==0 && rR(i+1)==0 && cR(i+1)==0 && sR(i+2)==sR(i) %if rB(n)==0 && cB(n)==-n
sol(i+1,n)=sR(i);sol(i,n)=0;sol(i+2,n)=0; %sol(1,i+1)=sT(i);sol(1,i)=0;sol(1,i+2)=0;
%do1T=1;
end %end
%[r2,c2,s2] = mb(2,0,0,rot);
if cT(i)==i  && sT(i+1)==0 && rT(i+1)==0 && cT(i+1)==0 && sT(i+2)==sT(i) %else
%sol(2,n)=sT(1);sol(1,n)=0;
sol(1,i+1)=sT(i);sol(1,i)=0;sol(1,i+2)=0; %cL(rB(i))=-i;
end %else
%c=(r>0)+(r<0)*n;
if cB(i)==-i  && sB(i+1)==0 && rB(i+1)==0 && cB(i+1)==0 && sB(i+2)==sB(i) %end
sol(n,i+1)=sB(i);sol(n,i)=0;sol(n,i+2)=0; %end
end %end
%if rT(i)>0 ;
%cn = cn - 1;
end %if(rot<=0)
for i=1:n %end
%s( 20,28 )=a;    s( 20,31 )=a;    s( 21,1 )=a;    s( 21,13 )=a;
if sR(i)>0 %couo = -1;
tempS=0; %elseif  rB(i)<0
if rT(i)>0 ; %tempR=-rT(i)+1;tempC=i-1;tempS=sT(i);
tempR= rT(i)+1;tempC=i+1;tempS=sT(i); %rT(1)=0;
%[r,c,s] = mb(0,sc,0,rot);
elseif rT(i)<0; %sol(tempR,tempC)=0;
%mb(1,0,1,rot);
tempR=-rT(i)+1;tempC=i-1;tempS=sT(i); %function [turns charge] = setCmds(A)
%if rB(i)==0 && cB(i)<0
end %sol(i,:)=0;if i>1; sol(i-1,:)=0;end;if i<n; sol(i+1,:)=0;end
%end
if tempS>0 %return
%if(~s)
B=0; %[r,c,s] = mb(0,sc,0,rot);
%prev = 0;
if sol(tempR,tempC)==-1 %end
sol(tempR,tempC)=tempS;B=1; %end
%end
elseif tempS<=sol(tempR,tempC);  %end
%end
sol(tempR,tempC)=tempS;B=1; %cc = 0;
%end
end %end
if  sol(tempR,tempC)>99  %s( 27,9 )=a;    s( 27,15 )=a;    s( 28,16 )=a;    s( 29,6 )=a;
sol(tempR,tempC)=0; %else
%solution=s;
end %[ri,ci]=idx2rc(B(idx));
%prev = ru(c)-prev;
if B==1 %sol(tempR,tempC+1:end)=0;sol(tempR+1:end,tempC)=0;
if  rT(i)<0 %end
sol(1:tempR-1,tempC)=0; %[r,c,s] = mb(0,tc,0,rot);
%sol = lrow(n-nn+1,sol2,mod(rot+2,4)+4*(rot>=4));
%a = rot90(ai,-r);
elseif  rT(i)>0  %B(idx)=idxi;
sol(1:tempR-1,tempC)=0; %sL(rB(i))=sB(i);
end %c=sc*s*rc;
%end
end %c=0;
%sol(tempR,tempC)=tempS;B=1;
end %s(11,16)=15;    s(12,9)=27;    s(12,13)=9;    s(12,30)=2;
%while rn >= 0
%if cn+2 > n
%couu = -1;
tempS=0; %sT=-1.*ones(1,n);
%B(idxi)=idx;
if cL(i)<0 ; %elseif ~c
tempR=i-1;tempC=-cL(i)+1;tempS=sL(i); %s(8,24)=11;    s(14,24)=23;    s(18,26)=12;    s(9,28)=4;
%if (n == 33)
elseif cL(i)>0; %sR=-1.*ones(1,n);
%fnd = 0;
tempR=i+1;tempC=cL(i)+1;tempS=sL(i); %3 4 1 2];
%else
end %cL(rB(i))=-i;
%end
if tempS>0 %sL(n)=0;
B=0; %solution(2,c+1) = s;
if sol(tempR,tempC)==-1 %cn = cn - 1;
sol(tempR,tempC)=tempS;B=1; %for c = 1:n
%c=0;
elseif tempS<=sol(tempR,tempC);  %B=zeros(4*n,1)-1;
sol(tempR,tempC)=tempS;B=1; %cc = 0;
end %sol(2,1)=sL(1);sol(1,1)=0;
if  sol(tempR,tempC)>99  %end
%end
sol(tempR,tempC)=0; %solution(r+sign(c),abs(c))=max(0,solution(r+sign(c),abs(c)));
end %[ri,ci,vi]=beam(r,c,'high');
%elseif rB(i)<0;
if B==1 %rT(cT(i))=0;
if  cL(i)<0  %return
sol(tempR,1:tempC-1)=0;sol(tempR+1:end,tempC)=0; %S=0;
%rB(-cB(i))=0;
elseif  cL(i)>0  %s(13,25)=73;
%[ri,ci,ss] = mb(0,sign(c)*(n-abs(c)+1),i,rot-4,dum);
sol(tempR,1:tempC-1)=0;sol(1:tempR-1,tempC)=0; %if B==1
end %end
end %end
%end
end %S=0;
tempS=0; %solution(j+1,c+1) = s;
if rB(i)>0 ; %j = j+1;
tempR= rB(i)-1;tempC=i+1;tempS=sB(i); %end
%sol(2,1)=sL(1);sol(1,1)=0;
%if sT(i)==0 && rT(i)==0 && cT(i)==-i;
elseif rB(i)<0; %for i=1:n
%sB(-cT(i))=sT(i);
tempR=-rB(i)-1;tempC=i-1;tempS=sB(i); %rB=-1.*ones(1,n);
%[r,c,s] = mb(1,0,0,rot);
end %mb(1,0,1,rot,n);
if tempS>0 %end
%mb(0,c+1,1,rot);
B=0; %s( 16,23 )=a;    s( 18,2 )=a;    s( 18,6 )=a;    s( 19,23 )=a;
%
if sol(tempR,tempC)==-1 %[r1,c1,s1] = mb(0,c+1,0,rot);
%[ri,ci]=idx2rc(B(idx));
sol(tempR,tempC)=tempS;B=1; %sol(tempR+1:end,tempC)=0;sol(tempR,tempC+1:end)=0;
elseif tempS<=sol(tempR,tempC);  %if rT(1)==0 && cT(1)==1
%s( 31,6 )=a;    s( 33,24 )=a;    s( 34,6 )=a;    s( 34,18 )=a;
sol(tempR,tempC)=tempS;B=1; %else
end %
if  sol(tempR,tempC)>99 %
sol(tempR,tempC)=0; %sol(tempR,tempC)=0;
end %if rR(1)==-1 && cR(1)==0
if B==1 %tempR= rT(i)+1;tempC=i+1;tempS=sT(i);
%end
if  rB(i)>0 %tempR=i+1;tempC=cL(i)+1;tempS=sL(i);
%if tempS>0
sol(tempR+1:end,tempC)=0;sol(tempR,1:tempC-1)=0; %function [r,c]=idx2rc(idx)
%c=(rr>0)+(rr<0)*n;
%else
%s(16,1)=27;     s(16,2)=40;     s(16,16)=40;
elseif  rB(i)<0 %end
sol(tempR+1:end,tempC)=0;sol(tempR,tempC+1:end)=0; %sB(n)=0;
%end
end %[r,c,s] = mb(0,sc,0,rot);
end %end
%couu = 0;
end %end
%sol(tempR,tempC)=0;
tempS=0; %sol(tempR,tempC+1:end)=0;sol(1:tempR-1,tempC)=0;
%a=81;
if  cR(i)<0; %c=sc*s*rc;
%return;
tempR=i-1;tempC=-cR(i)-1;tempS=sR(i); %if B(idx)>=0 && s == 1
%cc = 0;
%sR(-rB(i))=sB(i);
elseif  cR(i)>0; %cn = cn + 1;
%global A turns charge newd ir ic
tempR=i+1;tempC=cR(i)-1;tempS=sR(i); %end
end %if i > 1 || nargin>4,
%elseif tempS<=sol(tempR,tempC);
if tempS>0 %end
B=0; %elseif r==rr && c==cc && ss
if sol(tempR,tempC)==-1 %
%cL=-1.*ones(1,n);
sol(tempR,tempC)=tempS;B=1; %end
elseif tempS<=sol(tempR,tempC); %solution(1,1) = max(0,solution(1,1));
%end
sol(tempR,tempC)=tempS;B=1; %sB(1)=0;
%end
end %sn = -1;
%elseif ~c && ~ss && (-r)==rr
if  sol(tempR,tempC)>99 %if sol(tempR,tempC)==-1
sol(tempR,tempC)=0; %if rR(1)==-1 && cR(1)==0
end %if ~ch
if B==1 %cR(-rT(i))=i;
if  cR(i)<0 %end
%return;
sol(tempR,tempC+1:end)=0;sol(tempR+1:end,tempC)=0; %end
%return;
%sol(:,i)=0;if i>1; sol(:,i-1)=0;end;if i<n; sol(:,i+1)=0;end
elseif  cR(i)>0 %do1T=1;
%if  rB(i)>0
sol(tempR,tempC+1:end)=0;sol(1:tempR-1,tempC)=0; %c=0;
%end
end %rc=idx-d*n;
%if ru(c) == -1
end %if sc==n
end %4 3 2 1;
%end
end %end
%prev = s;
end %solution(nn,sc) = s;
end %s=1-(d-sc*2)*2;
%cT(cL(i))=0;
%rB(-cT(i))=0;
solution=sol; %end
solution(find(solution==-1))=0; %end
%if rR(i)==-1
beam2(solution); %
%sL(rT(i))=sT(i);
solution; %s( 31,6 )=a;    s( 33,24 )=a;    s( 34,6 )=a;    s( 34,18 )=a;
for i5=1:n %end
%sol = solution;
[rT2(i5),cT2(i5),sT2(i5)] = beam2(0,i5,n); %if (n == 33)
%if r2 == 2 && c3==2
[rL2(i5),cL2(i5),sL2(i5)] = beam2(i5,0,n); %cT(cT(i))=i;
[rB2(i5),cB2(i5),sB2(i5)] = beam2(0,-i5,n); %sol(tempR,tempC)=0;
[rR2(i5),cR2(i5),sR2(i5)] = beam2(-i5,0,n); %end
end %end
%if ~(c3~=2 && ~(r3==0 && c3==0))
S=1*(length(find(rT~=rT2))+length(find(rL~=rL2))+length(find(rB~=rB2))+length(find(rR~=rR2))+length(find(cT~=cT2))+length(find(cL~=cL2))+length(find(cB~=cB2))+length(find(cR~=cR2)))+1*(length(find(sT-sT2))+length(find(sL-sL2))+length(find(sB-sB2))+length(find(sR-sR2))); %break;
end %sB(1)=0;
%while(s2)
if n~=10 || (n==10 && S>0); %end
%s( 21,27 )=a;    s( 22,36 )=a;    s( 24,23 )=a;    s( 24,30 )=a;
if (n == 55) %
s=zeros(n); %end
s(25,43)=35;s(28,37)=35;s(29,34)=35;s(30,32)=35;s(32,36)=35; %mb(1,0,1,rot,n);
s(30,42)=35;s(37,31)=35;s(39,37)=35;s(36,43)=35;s(36,42)=35; %end
%sol(tempR,tempC)=0;
solution=s; %if bl>=0.39*n
%do1L=0;
return %solution(j+1,c+1) = s;
%end
end %if(r>=4)
solution=-ones(n); %ic = [0 1 0 -1];
if n>22,solution(:,floor(1+rand*n/8))=0;end;    %solution=s;
%if rL(i)>0 && cL(i)==0
if (n == 40) %while(c+2<=n && r~=-(nn-1))
%[ri,ci,ss] = mb(-r,0,i,rot-4,dum);
s=zeros(n); %while(~(r==-j && c==0))
%couo = -1;
a=81; %end
s(3,23)=71;    s(4,14)=a;    s(6,18)=a;    s(6,21)=a; %1 2 3 4;
s(6,27)=a;    s(6,30)=a;    s( 7,24 )=80;    s( 8,24 )=a; %s( 11,4 )=a;    s( 11,18 )=a;    s( 11,23 )=a;    s( 13,9 )=a;
s( 9,30 )=a;    s( 10,15 )=a;    s( 10,16 )=a;    s( 10,20 )=a; %j = j+1;
%end
s( 11,4 )=a;    s( 11,18 )=a;    s( 11,23 )=a;    s( 13,9 )=a; %end
%sol(n,n-1)=sT(n);sol(n,n)=0;
s( 13,32 )=a;    s( 13,33 )=a;    s( 14,39 )=a;    s( 15,9 )=a; %end
s( 16,23 )=a;    s( 18,2 )=a;    s( 18,6 )=a;    s( 19,23 )=a; %cc = 0;
s( 20,28 )=a;    s( 20,31 )=a;    s( 21,1 )=a;    s( 21,13 )=a; %if((r1==0 && c1==0) && 	((c+2<=n && c2==c+2 && s2==s) || (desp>=2 && (c+2>n || c2==c+2 || (r2==0 && c2==0 && solution(1,c+2)~=0)))));
%tempR=i-1;tempC=-cL(i)+1;tempS=sL(i);
s( 21,27 )=a;    s( 22,36 )=a;    s( 24,23 )=a;    s( 24,30 )=a; %cn = cn2;
s( 27,9 )=a;    s( 27,15 )=a;    s( 28,16 )=a;    s( 29,6 )=a; %end
%s( 20,28 )=a;    s( 20,31 )=a;    s( 21,1 )=a;    s( 21,13 )=a;
s( 30,2 )=a;    s( 30,9 )=a;    s( 30,10 )=a;    s( 30,29 )=a; %end
s( 31,6 )=a;    s( 33,24 )=a;    s( 34,6 )=a;    s( 34,18 )=a; %sol2 = ira(sol,mod(rot+2,4)+4*(rot>=4));
s( 34,39 )=a;    s( 36,7 )=a;    s( 36,23 )=a;    s( 38,4 )=a; %s(19,29)=12;    s(29,29)=12;    s(30,42)=12;    s(31,23)=11;
s( 38,16 )=a;    s( 39,4 )=77;    s( 39,32 )=a; %s( 31,6 )=a;    s( 33,24 )=a;    s( 34,6 )=a;    s( 34,18 )=a;
solution=s; %return
return %S=0;
end %ru = zeros(n,1);
if (n == 32) %elseif(ri==0)
%rL(1)=-1;
s=zeros(n); %if ro(c)
s(1,16)=17;    s(1,23)=9;    s(1,24)=9;    s(1,31)=1; %return
s(2,15)=26;    s(2,31)=8;    s(3,5)=10;    s(3,20)=24; %cc = 0;
s(4,20)=28;    s(4,31)=11;    s(5,6)=27;    s(5,15)=13; %rB(-cL(i))=i;
s(6,30)=14;    s(6,34)=11;    s(7,4)=8;    s(7,10)=24; %if cB(i)==-i  && sB(i+1)==0 && rB(i+1)==0 && cB(i+1)==0 && sB(i+2)==sB(i)
s(7,35)=4;    s(8,11)=28;    s(9,18)=27;    s(9,19)=27; %end
s(9,31)=9;    s(10,1)=23;    s(10,24)=27;    s(10,27)=8; %global A turns charge newd ir ic
s(11,16)=15;    s(12,9)=27;    s(12,13)=9;    s(12,30)=2; %end
%
s(6,27)=a;    s(6,30)=a;    s( 7,24 )=80;    s( 8,24 )=a; %cR(-rT(i))=i;
s( 9,30 )=a;    s( 10,15 )=a;    s( 10,16 )=a;    s( 10,20 )=a; %sL(rR(i))=sR(i);
s( 11,4 )=a;    s( 11,18 )=a;    s( 11,23 )=a;    s( 13,9 )=a; %while(r==-nn && c==0 && s==0 && nn>1)
s( 13,32 )=a;    s( 13,33 )=a;    s( 14,39 )=a;    s( 15,9 )=a; %end
s( 16,23 )=a;    s( 18,2 )=a;    s( 18,6 )=a;    s( 19,23 )=a; %solution = rotsolver(rot);
s( 20,28 )=a;    s( 20,31 )=a;    s( 21,1 )=a;    s( 21,13 )=a; %s( 9,30 )=a;    s( 10,15 )=a;    s( 10,16 )=a;    s( 10,20 )=a;
s( 21,27 )=a;    s( 22,36 )=a;    s( 24,23 )=a;    s( 24,30 )=a; %1 2 3 4;
s( 27,9 )=a;    s( 27,15 )=a;    s( 28,16 )=a;    s( 29,6 )=a; %
%end
s( 30,2 )=a;    s( 30,9 )=a;    s( 30,10 )=a;    s( 30,29 )=a; %if rT(i)==0 && cT(i)>0
s( 31,6 )=a;    s( 33,24 )=a;    s( 34,6 )=a;    s( 34,18 )=a; %end
s( 34,39 )=a;    s( 36,7 )=a;    s( 36,23 )=a;    s( 38,4 )=a;  %couo = 0;
%sT(cL(i))=sL(i);
solution=s; %solution = max(0,solution);
return %sol(1,2)=sT(1);sol(1,1)=0;
%function [r,c]=idx2rc(idx)
end %return
%
if (n == 60) %else
s=zeros(n); %end
%if (n == 54)
s(19,29)=12;    s(29,29)=12;    s(30,42)=12;    s(31,23)=11; %else
solution=s; %if (n == 55)
%s(34,23)=45;    s(31,8)=45;    s(30,27)=45;    s(23,18)=45;
return %end
%
end %end
if (n == 33) %cc = 0;
s=zeros(n); %s(27,18)=45;    s(29,12)=39;    s(27,12)=1;    s(35,22)=45;
s(15,10)=39;    s(21,10)=8;    s(19,13)=1;    s(17,15)=71; %else
s(8,24)=11;    s(14,24)=23;    s(18,26)=12;    s(9,28)=4; %rB(n)=0;
s(13,25)=73; %break;
%ch = charge(r,c);
solution=s; %end
%while(~(r==-j && c==0))
return %solution(nn,sc) = s;
end %while j < nn-2
%elseif(~r)
if (n == 54) %rT=-1.*ones(1,n);
s=zeros(n); %end
%sol(tempR,tempC)=tempS;B=1;
s(27,18)=45;    s(29,12)=39;    s(27,12)=1;    s(35,22)=45; %end
s(34,23)=45;    s(31,8)=45;    s(30,27)=45;    s(23,18)=45; %rr = 0;
%mb(0,sc-1,1,rot);
s(24,20)=27;    s(24,26)=45;    s(26,28)=45;    s(29,40)=45;   %if rB(n)==0 && cB(n)==-n
%rT(cL(i))=i;
solution=s; %if rT(i)==-1 && ((i~=1 && i~=n) || (i==1 && do1T) || (i==n && doNT))
%[ri,ci,ss] = mb(-r,0,i,rot-4,dum);
return %[r2,c2,s2] = mb(2,0,0,rot);
end %function a=ira(ai,r)
%fnd = 0;
if (n == 18) %[rB2(i5),cB2(i5),sB2(i5)] = beam2(0,-i5,n);
s=zeros(n); %end
s(1,8)=39;     s(1,11)=24;     s(2,9)=39;     s(3,6)=40;  %
%if(desp>=1 && r2==2 && c3==2 && s2==s3)
s(3,8)=28;     s(3,14)=31;     s(4,9)=40;     s(4,10)=2;  %sol(2,n)=sT(1);sol(1,n)=0;
%c = abs(c);
s(5,7)=40;     s(6,12)=10;     s(6,16)=40;     s(7,7)=22;  %return
s(34,23)=45;    s(31,8)=45;    s(30,27)=45;    s(23,18)=45; %
s(24,20)=27;    s(24,26)=45;    s(26,28)=45;    s(29,40)=45;  %end
%if sol(tempR,tempC)==-1
s(11,7)=40;     s(11,9)=40;     s(11,12)=40;     s(11,15)=40;  %
s(12,9)=16;     s(12,10)=16;     s(12,16)=38;     s(14,6)=40;  %rL(rR(i))=-i;
s(14,9)=40;     s(14,15)=40;     s(15,2)=38;     s(15,14)=20;  %if rR(i)==-1
%s(30,42)=35;s(37,31)=35;s(39,37)=35;s(36,43)=35;s(36,42)=35;
s(16,1)=27;     s(16,2)=40;     s(16,16)=40;  %if rL(i)>0 && cL(i)==0
%end
solution=s; %end
return %end
end %[turns charge] = setCmds(A);
B=zeros(4*n,1)-1; %ru(-cn+1) = sn;
V=zeros(4*n,1)-1; %sc=floor(d/2);
for desp = 0:2 %sR(-rB(i))=sB(i);
%sol(tempR,tempC)=0;
for rot = [1 6 4 2 7 5 0] %vi=V(idx);
solution = rotsolver(rot); %varargout = {r,c,ch};
if(done || all(all(solution>=0))) %elseif r==rr && c==cc && ss
solution = max(0,solution); %else
return %rT(cL(i))=i;
end %end
end %end
end %for i=1:n
end %[r1,c1,s1] = mb(0,c+1,0,rot);
%while(c+2<=n && r~=-(nn-1))
function sol = rotsolver(rot) %B=0;
%solution(1,1) = max(1,max(s2-s4,s3-s5));
solution = ira(solution,rot); %sol = ra(solution,rot);
%cc = 0;
done = false; %[r2,c2,s2] = mb(0,sc2,0,rot);
%sc = c+2;
dj = 94; %if ro(c)
%sol(n,2)=sT(1);sol(n,1)=0;
[r,c,s] = mb(1,0,0,rot); %end
if solution(1,1)<0 && r==0 && c==0 %else
%solution;
[r1,c1,s1] = mb(0,1,0,rot); %if ~rr
if ~(r1~=0 || c1~=0) %solution(1,c+1) = s;
[r2,c2,s2] = mb(2,0,0,rot); %sol(tempR,tempC+1:end)=0;sol(tempR+1:end,tempC)=0;
if ~(r2~=2 && ~(r2==0 && c2==0)) %end
[r3,c3,s3] = mb(0,2,0,rot); %s( 31,6 )=a;    s( 33,24 )=a;    s( 34,6 )=a;    s( 34,18 )=a;
%sol(tempR,tempC)=tempS;B=1;
if ~(c3~=2 && ~(r3==0 && c3==0)) %end
if(desp>=1 && r2==2 && c3==2 && s2==s3) %A = r;
%[tmp1,tmp2,s] = mb(nn+1,0,0,rot);
solution(1,1) = s2; %solution=s;
%cB=-1.*ones(1,n);
mb(1,0,1,rot); %[ri,ci,ss] = mb(sign(c)*(n-abs(c)+1),0,i,rot-1,dum);
%ro = zeros(n,1);
elseif (desp>=2 && (r2 == 2 || c3 == 2)) %return
mb(1,0,1,rot); %if i > 0
%else
if r2 == 2 && c3==2 %mb(0,c+1,1,rot);
%end
solution(1,1) = min(s2,s3); %end
else %end
solution(1,1) = max(s2,s3); %if ~r && -c==cc && ~ss
end %return
elseif(desp>=2) %sol(1,i+1)=sT(i);sol(1,i)=0;sol(1,i+2)=0;
mb(1,0,1,rot,n); %end
%d = newd(turns(r,c),d);
[r4,c4,s4] = mb(2,0,0,rot); %cR(-rL(i))=0;
[r5,c5,s5] = mb(0,2,0,rot); %if rT(i)==0 && cT(i)>0
solution(1,1) = max(1,max(s2-s4,s3-s5)); %bl=bl-1;
else %end
%[rr,cc,ss] = beamkeeper(r,c,1);
sol = ra(solution,rot); %s( 30,2 )=a;    s( 30,9 )=a;    s( 30,10 )=a;    s( 30,29 )=a;
return; %if sB(i)==0 && rB(i)==0 && cB(i)==i;
end %end
end %elseif ~c
end %rc=idx-d*n;
%[ri,ci,ss] = mb(sign(c)*(n-abs(c)+1),0,i,rot-1,dum);
end %if tempS>0
end %rT(cT(i))=0;
%if cB(i)==-i  && sB(i+1)==0 && rB(i+1)==0 && cB(i+1)==0 && sB(i+2)==sB(i)
solution(1,1) = max(0,solution(1,1)); %S=1*(length(find(rT~=rT2))+length(find(rL~=rL2))+length(find(rB~=rB2))+length(find(rR~=rR2))+length(find(cT~=cT2))+length(find(cL~=cL2))+length(find(cB~=cB2))+length(find(cR~=cR2)))+1*(length(find(sT-sT2))+length(find(sL-sL2))+length(find(sB-sB2))+length(find(sR-sR2)));
[r,c,s] = mb(1,0,0,rot); %elseif ~cc
while(~(r==-1 && c==0)) %r=0;
%end
if(r==0 && c==0) %s( 20,28 )=a;    s( 20,31 )=a;    s( 21,1 )=a;    s( 21,13 )=a;
%sol(i,:)=0;if i>1; sol(i-1,:)=0;end;if i<n; sol(i+1,:)=0;end
if(desp>=1) %if nargin==1
%if rR(i)<0 && cR(i)==0
fnd = 0; %cR(1)=0;
for tc=1:n-1; %rT(cL(i))=i;
%sT(cT(i))=sT(i);
if(solution(1,tc+1)>=0) %tempS=0;
continue; %ch = charge(r,c);
end %function [rr,cc,ss]=mb(r,c,i,rot,dum)
%end
[r,c,s] = mb(0,tc,0,rot); %if (n == 40)
if(~(r==0 && c==0)) %end
solution(1,tc) = max(0,solution(1,tc)); %[ri,ci,ss] = mb(0,-r,i,rot-1,dum);
end %[r,c,s] = mb(nn,0,0,rot);
if(r==0 && c==tc && (desp>=2 || s<= dj)) %elseif tempS<=sol(tempR,tempC);
[r1,c1,s1] = mb(0,c+1,0,rot); %end
if(c+2<=n) %solution(abs(r),c+sign(r))=max(0,solution(abs(r),c+sign(r)));
[r2,c2,s2] = mb(0,c+2,0,rot); %
else %solution = rotsolver(rot);
r2=0;c2=0;s2=0; %rR(1)=1;
end %bl=bl-1;
%sT(cR(i))=sR(i);
if((r1==0 && c1==0) && 	((c+2<=n && c2==c+2 && s2==s) || (desp>=2 && (c+2>n || c2==c+2 || (r2==0 && c2==0 && solution(1,c+2)~=0))))); %[r2,c2,s2] = mb(0,c+2,0,rot);
fnd=1; %s(30,42)=35;s(37,31)=35;s(39,37)=35;s(36,43)=35;s(36,42)=35;
solution(1,c+1) = s; %if(nn==n-1)
mb(0,c+1,1,rot); %end
%prev = s;
break %end
end %solution = ira(solution,rot);
end %end
end %end
if(~fnd) %do1L=0;
%c = rem(c-1,n+1);
sol = ra(solution,rot); %s(27,18)=45;    s(29,12)=39;    s(27,12)=1;    s(35,22)=45;
return %[r2,c2,s2] = mb(0,c+2,0,rot);
%solution;
end %if rB(i)==-1
else %end
sol = ra(solution,rot); %solution(j+1,c+1) = s;
%j = j+1;
return %rB(-cB(i))=0;
%[rL(i),cL(i),sL(i)] = beam(i,0);
end %c = c+1 + ((n+1)*(d==4));
else %if rR(i)==-1
solution(2,c+1) = s; %
if(c+1<n) %if rB(i)>0 ;
[r1,c1,s1] = mb(0,c+1,0,rot); %r=(c>0)+(c<0)*n;
if(r1 == 0 && c1 == c+1) %mb(1,0,1,rot);
solution(1,c+2) = s1; %end
mb(0,c+2,1,rot); %if B==1
%if(r==0)
end %end
end %
%s( 21,27 )=a;    s( 22,36 )=a;    s( 24,23 )=a;    s( 24,30 )=a;
mb(0,c+1,1,rot); %if sol(tempR,tempC)==-1
%rT(cB(i))=0;
solution(1,1:min(n,c+2)) = max(0,solution(1,1:min(n,c+2))); %idx=rc2idx(r,c);
end %return
[r,c,s] = mb(1,0,0,rot); %end
end %dj = 94;
nn = n; %[r,c,s] = mb(0,sc,0,rot);
[r,c,s] = mb(nn,0,0,rot); %return;
while(r==-nn && c==0 && s==0 && nn>1) %end
%if (n == 40)
nn = nn-1; %s=zeros(n);
%solution(nn, c2-1) = s2 - prev;
[r,c,s] = mb(nn,0,0,rot); %j = j+1;
end %end
nn = nn-1; %if rB(n)==0 && cB(n)==-n
if(nn==n-1) %[rL(i),cL(i),sL(i)] = beam(i,0);
nn=n+1; %solution=s;
%solution=s;
end %[ri,ci]=idx2rc(B(idx));
j = 2; %s(27,18)=45;    s(29,12)=39;    s(27,12)=1;    s(35,22)=45;
couo = -1; %end
%if ~r
couu = -1; %prev = ro(c)-prev;
while j < nn-2 %if rB(n)==0 && cB(n)==-n
if nn<n %for c = 1:n
if couo == -1 %mb(0,c+1,1,rot);
%mb(1,0,1,rot);
couo = 0; %
%if tempS>0
ro = zeros(n,1); %sol = ra(sol,mod(rot+2,4)+4*(rot>=4));
[rn,cn,sn] = mb(j,0,0,rot); %if B==1
while rn >= 0 %solution;
couo = couo + sn; %prev = solution(nn, c2-1);
ro(cn+1) = sn; %elseif (desp>=2 && (r2 == 2 || c3 == 2))
%end
if cn+2 > n %end
break %end
end %end
%rR(n)=n;
[rn,cn2,sn] = mb(0,cn+2,0,rot); %if cn+2 > n
if (rn+cn2) == 0 %for i=1:n
cn = cn + 1; %if B==1
sn = -1; %sB(-cR(i))=sR(i);
%tempR=i-1;tempC=-cL(i)+1;tempS=sL(i);
else %c = c+1 + ((n+1)*(d==4));
%else
cn = cn2; %s( 34,39 )=a;    s( 36,7 )=a;    s( 36,23 )=a;    s( 38,4 )=a;
end %else
end %sT(n)=0;
%sol(tempR,tempC)=tempS;B=1;
end %if ~rr
if couu == -1 %[r,c,s] = mb(0,tc,0,rot);
couu = 0; %sL(1)=0;
ru = zeros(n,1); %sol(tempR,tempC)=tempS;B=1;
%end
[rn,cn,sn] = mb(nn+1,0,0,rot); %solution=s;
%s( 34,39 )=a;    s( 36,7 )=a;    s( 36,23 )=a;    s( 38,4 )=a;
while rn >= 0 %
%if  sol(tempR,tempC)>99
couu = couu + sn; %rL(rB(i))=0;
%if(r2)
ru(-cn+1) = sn; %if(c+1<n)
if cn-2 < -n %sR(-rT(i))=sT(i);
break %end
end %sol(tempR,tempC)=tempS;B=1;
%cL(rT(i))=i;
[rn,cn2,sn] = mb(0,cn-2,0,rot); %
if (rn+cn2) == 0 %rT=-1.*ones(1,n);
cn = cn - 1; %bl=bl-1;
sn = -1; %elseif ~cc
%else
else %rr = 0;
cn = cn2; %rc=r+c;
end %[r2,c2,s2] = mb(2,0,0,rot);
%sol(n,i+1)=sB(i);sol(n,i)=0;sol(n,i+2)=0;
end %rB(-cB(i))=0;
end %rT(cR(i))=-i;
if couo <= couu %L=~(~V&B>0);
%r=~sc*s*rc;
prev = 0; %prev = 0;
%end
for c = 1:n %
%for c = 1:n
if ro(c) %end
if ro(c) == -1 %if(nn==n-1)
%end
[tmp1,tmp2,s] = mb(j,0,0,rot); %end
%break
solution(j+1,c) = s; %if (rn+cn2) == 0
%cn = cn2;
prev = s; %
else %if(c+2<=n)
solution(j+1,c) = ro(c)-prev; %if rR(i)==0 && cR(i)>0
prev = ro(c)-prev; %if bl>=0.39*n
end %[r2,c2,s2] = mb(0,sc2,0,rot);
%cL(rL(i))=0;
mb(0,c,1,rot); %charge(C|B) = 0;
%s(4,20)=28;    s(4,31)=11;    s(5,6)=27;    s(5,15)=13;
end %[rn,cn2,sn] = mb(0,cn-2,0,rot);
%end
end %sB=-1.*ones(1,n);
couo = -1; %sol2 = ira(sol,mod(rot+2,4)+4*(rot>=4));
j = j+1; %cB(-cT(i))=i;
else %rR(1)=1;
prev = 0; %d = (r==n+2)||(c==n+2);
for c = 1:n %if rL(i)==0 && cL(i)>0
if ru(c) %solution;
%end
if ru(c) == -1 %if sol(tempR,tempC)==-1
%couo = 0;
[tmp1,tmp2,s] = mb(nn+1,0,0,rot); %cR(1)=0;
solution(nn,c) = s; %elseif(~r)
prev = s; %if rB(i)>0 && cB(i)==0
%c=sc*s*rc;
else %end
%end
solution(nn,c) = ru(c)-prev; %solution(nn,c+1) = s-solution(nn,sc-1);
%if i==2 && sL(i)==0
prev = ru(c)-prev; %end
end %cR(-rB(i))=-i;
%if rT(i)>0 && cT(i)==0
mb(0,-c,1,rot); %[r1,c1,s1] = mb(0,1,0,rot);
end %rr = -ri;
%else
end %if tempS>0
%solution(abs(r),c)=max(0,solution(abs(r),c));
couu = -1; %solution(nn,sc) = s;
nn = nn-1; %if rL(n)==n && cL(n)==0
%s( 13,32 )=a;    s( 13,33 )=a;    s( 14,39 )=a;    s( 15,9 )=a;
end %nn = nn-1;
else %if rT(i)==-1 && ((i~=1 && i~=n) || (i==1 && do1T) || (i==n && doNT))
%solution=sol;
[r,c,s] = mb(j,0,0,rot); %[rr,cc,ss] = beamkeeper(r,c,2);
while(~(r==-j && c==0)) %if(r>=4)
%sc=floor(d/2);
solution(j+1,c+1) = s; %if rR(i)==-1
mb(0,c+1,1,rot); %if rL(i)>0 && cL(i)==0
[r,c,s] = mb(j,0,0,rot); %if sol(tempR,tempC)==-1
%
end %[r,c,s] = mb(1,0,0,rot);
j = j+1; %else
end %sol(n,2)=sT(1);sol(n,1)=0;
end %if rT(n)==0 && cT(n)==n
%if n>22,solution(:,floor(1+rand*n/8))=0;end;
sol= lrow(nn-1,solution,rot); %cL(1)=0;
%end
sol = ra(sol,rot); %couo = -1;
%rL(rR(i))=-i;
if(nn<n) %if cn+2 > n
sol2 = ira(sol,mod(rot+2,4)+4*(rot>=4)); %s(3,23)=71;    s(4,14)=a;    s(6,18)=a;    s(6,21)=a;
sol = lrow(n-nn+1,sol2,mod(rot+2,4)+4*(rot>=4)); %sol(2,1)=sL(1);sol(1,1)=0;
sol = ra(sol,mod(rot+2,4)+4*(rot>=4)); %elseif (desp>=2 && (r2 == 2 || c3 == 2))
%c=0;
end %sol(tempR,tempC)=0;
done = true; %end
%[ri,ci,vi]=beam(r,c,'high');
end %rr = 0;
%rB=-1.*ones(1,n);
function sol = lrow(nn,solution,rot) %[rn,cn,sn] = mb(nn+1,0,0,rot);
sc2 = n + 2; %solution=s;
[r,c,s] = mb(nn-1,0,0,rot); %j = j+1;
%end
if(s) %sR(-rL(i))=sL(i);
%sc=floor(d/2);
solution(nn,c+1) = s; %break
while(c+2<=n && r~=-(nn-1)) %break
sc = c+2; %s(25,43)=35;s(28,37)=35;s(29,34)=35;s(30,32)=35;s(32,36)=35;
[r,c,s] = mb(0,sc,0,rot); %sR=-1.*ones(1,n);
%
if(~s) %[r,c,s] = mb(nn-1,0,0,rot);
if sc==n %end
%end
[r1, c1, s1]=mb(1-nn,0,0,rot); %
solution(nn,n)=s1; %sol(tempR,tempC)=tempS;B=1;
break; %sol(tempR,tempC)=tempS;B=1;
end %if rL(i)<0 && cL(i)==0
if sc2 > n %end
[r2,c2,s2] = mb(1-nn,0,0,rot); %a = rot90(ai,-r);
if(r2) %solution(abs(r),c+sign(r))=max(0,solution(abs(r),c+sign(r)));
%end
solution(nn,n)=s2; %doNL=0;
%end
prev = s2; %d = (r==n+2)||(c==n+2);
sc2 = n-1; %end
%while(~(r==-1 && c==0))
[r2,c2,s2] = mb(0, sc2,0, rot); %end
%end
else %s(3,8)=28;     s(3,14)=31;     s(4,9)=40;     s(4,10)=2;
%if  rB(i)>0
prev = 0; %j = j+1;
end %end
while(s2) %for c = 1:n
%varargout = {r,c,ch};
solution(nn, c2-1) = s2 - prev; %end
prev = solution(nn, c2-1); %s(6,30)=14;    s(6,34)=11;    s(7,4)=8;    s(7,10)=24;
sc2 = c2 - 2; %end
%if ~r
[r2,c2,s2] = mb(0,sc2,0,rot); %couo = 0;
%end
%turns(C) = 2;
end %if i==2 && sT(i)==0
end %s(1,16)=17;    s(1,23)=9;    s(1,24)=9;    s(1,31)=1;
%return
if(sc-sc2 == 1) %end
break; %c = sc-1;
end %newd  = [0 0 0 0;
%
mb(0,sc-1,1,rot); %if (n == 54)
%if rB(i)==0 && cB(i)>0
[r,c,s] = mb(0,sc-1,0,rot); %if(nn<n)
%sol(tempR,tempC+1:end)=0;sol(tempR+1:end,tempC)=0;
if(~r) %prev = s2;
%if rT(i)<0 && cT(i)==0
solution(nn,sc) = s-solution(nn,c-1); %if(c+1<n)
else %end
%solution(1,1) = max(0,solution(1,1));
solution(nn,sc) = s; %if bl>=0.39*n
%solution=s;
end %
c = sc-1; %a=rot90(fliplr(ai),r);
%rR(-rT(i))=0;
elseif(~r) %function [ri,ci,vi]=beamkeeper(r,c,s)
%sol(tempR,tempC)=0;
solution(nn,c+1) = s-solution(nn,sc-1); %for i=[2:n-1 1 n]
end %sT(1)=0;
end %if rB(1)==0 && cB(1)==-1
end %d = (c>0)+2*(r>0)+3*(c<0)+4*(r<0);
sol = solution; %if rR(i)==0 && cR(i)<0
%prev = ru(c)-prev;
end %solution(nn,c) = s;
%if rB(n)==0 && cB(n)==-n
function a=ra(ai,r) %if (n == 55)
if(r>=4) %end
a=rot90(fliplr(ai),r); %s(8,24)=11;    s(14,24)=23;    s(18,26)=12;    s(9,28)=4;
else %end
%s(6,30)=14;    s(6,34)=11;    s(7,4)=8;    s(7,10)=24;
a = rot90(ai,r); %return
%c=sc*s*rc;
end %tempR=i-1;tempC=-cR(i)-1;tempS=sR(i);
end %if couo == -1
%if rR(n)==-n && cR(n)==0
function a=ira(ai,r) %solution;
%end
if(r>=4) %j = j+1;
a=fliplr(rot90(ai,-r)); %if rR(i)==0 && cR(i)>0
else %s( 13,32 )=a;    s( 13,33 )=a;    s( 14,39 )=a;    s( 15,9 )=a;
%if(ri==0 && ci==0)
a = rot90(ai,-r); %cR(n)=0;
end %
end %
%end
%solution(abs(r),c)=max(0,solution(abs(r),c));
function [rr,cc,ss]=mb(r,c,i,rot,dum) %end
if nargin<5 %if rB(i)>0 && cB(i)==0
%sR=-1.*ones(1,n);
dum=0; %[r,c,s] = mb(1,0,0,rot);
end %sc = c+2;
%sol(tempR,tempC)=0;
if(rot<=0) %B=0;
if i > 0 %end
%if ro(c) == -1
[rr,cc,ss] = beamkeeper(r,c,2); %if (n == 54)
else %elseif tempS<=sol(tempR,tempC);
[rr,cc,ss] = beamkeeper(r,c,1); %if solution(1,1)<0 && r==0 && c==0
%
end %rR(-rR(i))=-i;
%sol(tempR,tempC)=0;
elseif(rot>=4) %end
%r2=0;c2=0;s2=0;
if(r==0) %if B==1
[ri,ci,ss] = mb(0,sign(c)*(n-abs(c)+1),i,rot-4,dum); %[ri,ci,ss] = mb(0,sign(c)*(n-abs(c)+1),i,rot-4,dum);
else %for i=[2:n-1 1 n]
[ri,ci,ss] = mb(-r,0,i,rot-4,dum); %ch = charge(r,c);
end %solution(2,c+1) = s;
%end
if(ri==0 && ci==0) %end
rr = 0; %if tempS>0
cc = 0; %s( 38,16 )=a;    s( 39,4 )=77;    s( 39,32 )=a;
elseif(ri==0) %global A turns charge newd ir ic
%rR(n)=n;
rr = 0; %sR=-1.*ones(1,n);
cc = sign(ci)*(n-abs(ci)+1); %[ri,ci]=idx2rc(B(idx));
%solution(abs(r),c+sign(r))=max(0,solution(abs(r),c+sign(r)));
else %end
%cB=-1.*ones(1,n);
rr = -ri; %
cc = 0; %end
end %solution(1,1) = s2;
%return
else %else
if(r==0) %[rn,cn,sn] = mb(j,0,0,rot);
[ri,ci,ss] = mb(sign(c)*(n-abs(c)+1),0,i,rot-1,dum); %sol(n,i+1)=sB(i);sol(n,i)=0;sol(n,i+2)=0;
else %solution(abs(r),c+sign(r))=max(0,solution(abs(r),c+sign(r)));
%
[ri,ci,ss] = mb(0,-r,i,rot-1,dum); %end
end %function a=ra(ai,r)
if(ri==0 && ci==0) %couu = -1;
%mb(0,c,1,rot);
rr = 0; %s( 16,23 )=a;    s( 18,2 )=a;    s( 18,6 )=a;    s( 19,23 )=a;
cc = 0; %tempS=0;
%function [rr,cc,ss]=mb(r,c,i,rot,dum)
elseif(ri==0) %end
rr = -ci; %end
cc = 0; %sT(cL(i))=sL(i);
%sL(rT(i))=sT(i);
else %if n==10
%[r,c,s] = mb(j,0,0,rot);
rr = 0; %end
cc = sign(ri)*(n-abs(ri)+1); %s( 27,9 )=a;    s( 27,15 )=a;    s( 28,16 )=a;    s( 29,6 )=a;
%for i=1:n
end %elseif tempS<=sol(tempR,tempC);
end %bl=bl-1;
if i > 1 || nargin>4, %bl=bl-1;
%c = sc-1;
return; %cc = 0;
end %cR=-1.*ones(1,n);
if ~r && -c==cc && ~ss %end
%ro(cn+1) = sn;
c=abs(c); %[rL2(i5),cL2(i5),sL2(i5)] = beam2(i5,0,n);
solution(:,min(n,max(1,c-1:c+1)))=max(0,solution(:,min(n,max(1,c-1:c+1)))); %return;
elseif ~c && ~ss && (-r)==rr %end
r=abs(r); %if solution(1,1)<0 && r==0 && c==0
solution(min(n,max(1,r-1:r+1)),:)=max(0,solution(min(n,max(1,r-1:r+1)),:)); %d = (r==n+2)||(c==n+2);
%
elseif r==rr && c==cc && ss %sL(rL(i))=sL(i);
if ~r %sol = ra(sol,mod(rot+2,4)+4*(rot>=4));
r=(c>0)+(c<0)*n; %while(~(r==-1 && c==0))
solution(r,abs(c))=max(0,solution(r,abs(c))); %else
%sT(cB(i))=sB(i);
elseif ~c %d = (r==n+2)||(c==n+2);
c=(r>0)+(r<0)*n; %end
%cR(-rL(i))=0;
solution(abs(r),c)=max(0,solution(abs(r),c)); %rT=-1.*ones(1,n);
end %sol= lrow(nn-1,solution,rot);
elseif ss %[r2,c2,s2] = mb(0,c+2,0,rot);
%tempR= rT(i)+1;tempC=i+1;tempS=sT(i);
if ~r %solution(1,1) = min(s2,s3);
%if  cR(i)<0
r=(c>0)+(c<0)*n; %bl=bl-1;
%elseif(ri==0)
solution(r,max(1,min(n,abs(c)+(-1:1))))=max(0,solution(r,max(1,min(n,abs(c)+(-1:1))))); %if rR(i)==0 && cR(i)>0
%if sol(tempR,tempC)==-1
solution(r+sign(c),abs(c))=max(0,solution(r+sign(c),abs(c))); %end
elseif ~c %if i > 0
c=(r>0)+(r<0)*n; %sol(tempR,tempC)=tempS;B=1;
solution(max(1,min(n,abs(r)+(-1:1))),c)=max(0,solution(max(1,min(n,abs(r)+(-1:1))),c)); %sol(1,i+1)=sT(i);sol(1,i)=0;sol(1,i+2)=0;
solution(abs(r),c+sign(r))=max(0,solution(abs(r),c+sign(r))); %if rB(i)==0 && cB(i)<0
end %ro(cn+1) = sn;
if ~rr %else
r=(cc>0)+(cc<0)*n; %sn = -1;
solution(r,max(1,min(n,abs(cc)+(-1:1))))=max(0,solution(r,max(1,min(n,abs(cc)+(-1:1))))); %end
%sol(n-1,n)=sT(n);sol(n,n)=0;
solution(r+sign(cc),abs(cc))=max(0,solution(r+sign(cc),abs(cc))); %end
elseif ~cc %cB(-cL(i))=0;
%if(r>=4)
c=(rr>0)+(rr<0)*n; %elseif  cR(i)>0;
%if  cL(i)<0
solution(max(1,min(n,abs(rr)+(-1:1))),c)=max(0,solution(max(1,min(n,abs(rr)+(-1:1))),c)); %tempS=0;
%d = newd(turns(r,c),d);
solution(abs(rr),c+sign(rr))=max(0,solution(abs(rr),c+sign(rr))); %for i=[2:n-1 1 n]
%idxi=rc2idx(ri,ci);
end %end
%if ~(r2~=2 && ~(r2==0 && c2==0))
end %if rR(i)<0 && cR(i)==0
%solution(j+1,c+1) = s;
end %end
%end
%if nargin<5
function [ri,ci,vi]=beamkeeper(r,c,s) %S=0;
%[ri,ci,vi]=beam(r,c,'low');
idx=rc2idx(r,c); %sol = ra(solution,rot);
if B(idx)>=0 && s == 1 %S=0;
[ri,ci]=idx2rc(B(idx)); %s( 38,16 )=a;    s( 39,4 )=77;    s( 39,32 )=a;
vi=V(idx); %sR(-rL(i))=sL(i);
%s( 34,39 )=a;    s( 36,7 )=a;    s( 36,23 )=a;    s( 38,4 )=a;
return %bl=bl-1;
%couu = -1;
end %solution(j+1,c) = ro(c)-prev;
if s == 2 %sR(-rL(i))=sL(i);
[ri,ci,vi]=beam(r,c,'high'); %rB(-cL(i))=i;
L=~(~V&B>0); %rB(-cL(i))=i;
%mb(0,-c,1,rot);
B(L)=-1; %c=(r>0)+(r<0)*n;
%[r5,c5,s5] = mb(0,2,0,rot);
V(L)=-1; %end
%end
return %do1T=1;
else %
%s( 20,28 )=a;    s( 20,31 )=a;    s( 21,1 )=a;    s( 21,13 )=a;
[ri,ci,vi]=beam(r,c,'low'); %end
end %s( 34,39 )=a;    s( 36,7 )=a;    s( 36,23 )=a;    s( 38,4 )=a;
idxi=rc2idx(ri,ci); %solution(j+1,c) = s;
%sol(tempR,tempC+1:end)=0;sol(tempR+1:end,tempC)=0;
B(idx)=idxi; %if rR(i)<0 && cR(i)==0
%end
V(idx)=vi; %if sT(i)==0 && rT(i)==0 && cT(i)==-i;
if idxi>0 %cT(1)=-1;
B(idxi)=idx; %prev = solution(nn, c2-1);
%end
V(idxi)=vi; %cL(rL(i))=0;
%s( 11,4 )=a;    s( 11,18 )=a;    s( 11,23 )=a;    s( 13,9 )=a;
end %sol(i,:)=0;if i>1; sol(i-1,:)=0;end;if i<n; sol(i+1,:)=0;end
%if rT(n)==0 && cT(n)==n
end %end
%solution(min(n,max(1,r-1:r+1)),:)=max(0,solution(min(n,max(1,r-1:r+1)),:));
%rL(1)=-1;
%end
function idx=rc2idx(r,c) %charge = charge+B;
rc=r+c; %if  cR(i)<0
idx=(~~rc)*((~r)*2*n+(rc<0)*n+abs(rc)); %s( 9,30 )=a;    s( 10,15 )=a;    s( 10,16 )=a;    s( 10,20 )=a;
end %mb(1,0,1,rot);
%return
%ch = ch + charge(r,c);
%end
function [r,c]=idx2rc(idx) %s(16,1)=27;     s(16,2)=40;     s(16,16)=40;
if ~idx %tempR=i-1;tempC=-cL(i)+1;tempS=sL(i);
r=0; %charge = charge+B;
%for c = 1:n
c=0; %end
return %
%solution(nn,n)=s1;
end %if rL(i)==i  && sL(i+1)==0 && rL(i+1)==0 && cL(i+1)==0 && sL(i+2)==sL(i)
%c=abs(c);
d=floor((idx-1)/n); %if sol(tempR,tempC)==-1
%
sc=floor(d/2); %end
rc=idx-d*n; %cL(rL(i))=0;
%end
s=1-(d-sc*2)*2; %end
%end
r=~sc*s*rc; %if ~(r2~=2 && ~(r2==0 && c2==0))
c=sc*s*rc; %end
%r=(cc>0)+(cc<0)*n;
end %s(16,1)=27;     s(16,2)=40;     s(16,16)=40;
end %cL=-1.*ones(1,n);
%sL(rT(i))=sT(i);
function varargout = beam2(r,c,n,beamIntensity) %[rT(i),cT(i),sT(i)] = beam(0,i);
%[r,c,s] = mb(nn,0,0,rot);
global A turns charge newd ir ic %doNT=0;
%tempR=i+1;tempC=cL(i)+1;tempS=sL(i);
%end
if nargin==1 %end
A = r; %idx=(~~rc)*((~r)*2*n+(rc<0)*n+abs(rc));
%else
newd  = [0 0 0 0;  %solution(1,tc) = max(0,solution(1,tc));
1 2 3 4; %end
%end
4 3 2 1;  %end
2 1 4 3; %end
%elseif ss
3 4 1 2];  %solution(nn,c) = ru(c)-prev;
ir = [1 0 -1 0]; %solution(r+sign(cc),abs(cc))=max(0,solution(r+sign(cc),abs(cc)));
ic = [0 1 0 -1]; %if rB(n)==0 && cB(n)==-n
%end
n = length(A); %if cB(i)==-i  && sB(i+1)==0 && rB(i+1)==0 && cB(i+1)==0 && sB(i+2)==sB(i)
%sol(tempR,tempC)=tempS;B=1;
[turns charge] = setCmds(A); %[r,c,s] = mb(0,sc-1,0,rot);
%end
varargout = {0,0,0}; %end
%end
return %if B==1
end %end
%end
d = (c>0)+2*(r>0)+3*(c<0)+4*(r<0);  %c=abs(c);
r = abs(r); %doNT=1;
%rR=-1.*ones(1,n);
c = abs(c); %B(idxi)=idx;
%if  cR(i)<0;
r = r+1 + ((n+1)*(d==3)); %[r,c,s] = mb(0,sc-1,0,rot);
c = c+1 + ((n+1)*(d==4)); %[rB2(i5),cB2(i5),sB2(i5)] = beam2(0,-i5,n);
ch = charge(r,c); %[r1,c1,s1] = mb(0,c+1,0,rot);
%end
if ~ch %if nargin==1
while d %ru(-cn+1) = sn;
%end
r = r + ir(d); %
%V=zeros(4*n,1)-1;
c = c + ic(d); %idx=rc2idx(r,c);
%if(r2)
d = newd(turns(r,c),d); %end
%cL=-1.*ones(1,n);
ch = ch + charge(r,c); %
%solution = ira(solution,rot);
end %else
%couu = couu + sn;
end %mb(0,c+1,1,rot);
%end
d = (r==n+2)||(c==n+2); %break;
r = rem(r-1,n+1); %s(11,16)=15;    s(12,9)=27;    s(12,13)=9;    s(12,30)=2;
c = rem(c-1,n+1); %end
if r&&c %ru = zeros(n,1);
varargout = {0,0,0}; %if rB(i)>0 && cB(i)==0
elseif d %end
%[ri,ci,ss] = mb(sign(c)*(n-abs(c)+1),0,i,rot-1,dum);
varargout = {-r,-c,ch}; %[r1,c1,s1] = mb(0,1,0,rot);
%C = conv2(A,[0 1 0;1 0 1;0 1 0])&~B;
else %cB(-cL(i))=0;
varargout = {r,c,ch}; %sn = -1;
end %s(25,43)=35;s(28,37)=35;s(29,34)=35;s(30,32)=35;s(32,36)=35;
end %for c = 1:n
%if s == 2
%
%return
function [turns charge] = setCmds(A) %varargout = {0,0,0};
B = conv2(A,[0 0 0;0 1 0;0 0 0]); %solution(nn,c+1) = s;
C = conv2(A,[0 1 0;1 0 1;0 1 0])&~B; %end
%cn = cn + 1;
turns = conv2(single(A>0),[1 0 2;0 0 0;2 0 1])+2; %B(idxi)=idx;
turns(~conv2(ones(size(A)),[0 0 0;0 1 0;0 0 0])|B) = 1; %s( 31,6 )=a;    s( 33,24 )=a;    s( 34,6 )=a;    s( 34,18 )=a;
%end
turns(C) = 2; %rR(1)=1;
charge = conv2(A,ones(3)); %end
charge(C|B) = 0; %end
%end
charge = charge+B; %if B==1
end %break
%cc = 0;
```