2006-12-06 09:00:00 UTC

GoBeef5 - generality

Status: Failed
Results:

BirdBrain
06 Dec 2006
ugh
Code
```function solution = solver(n)

rC = zeros(n,1);
cC = zeros(n,1);
sC = zeros(n,1);
solution = zeros(n);
edgesol = solution;
cornsol = solution;
sidesol = solution;
corn=0;
done=0;

%iter = 0;
while ~done
%if ~iter
[rC(1),cC(1),sC(1)] = beam(1,0);
if ~(abs(rC(1))+abs(cC(1))+abs(sC(1))) %true if sum=0, means absorbed on top row
[rC(2),cC(2),sC(2)] = beam(0,1);
if ~(abs(rC(1))+abs(cC(1))+abs(sC(1))) %true if sum=0, means absorbed on left side
[rC(3),cC(3),sC(3)] = beam(n,0);
if ~(abs(rC(1))+abs(cC(1))+abs(sC(1))) %true if sum=0, means absorbed on bottom row
[rC(4),cC(4),sC(4)] = beam(0,n);
if ~(abs(rC(1))+abs(cC(1))+abs(sC(1))) %true if sum=0, means absorbed on right side
if ~corn
cornsol = corners(n);
corn=1;
else
sidesol = sides(n);
end
else % not absorbed on right side
if (cC(4) == -n)&&(~sC(4))
solution = gobeef(0,n,0,n); %straight down through right side
done = 1;
else %reflected right
beam(rC(4)+1,0,'high')
edgesol(rC(4)+1,n-1) = sC(4);
done = 0;
end
end
else % not absorbed on bottom row
if (rC(3) == -n)&&(~sC(3))
solution = gobeef(n,0,0,n); %straight over through bottom row
done = 1;
else %reflected down
beam(0,cC(3)+1,'high')
edgesol(n-1,cC(3)+1) = sC(3);
done = 0;
end
end
else % not absorbed on left side
if (cC(2) == -1)&&(~sC(2))
solution = gobeef(0,1,1,n); %straight down through left side
done = 1;
else %reflected left
beam(rC(2)+1,0,'high')
edgesol(rC(2)+1,2) = sC(2);
done = 0;
end
end
else  % not absorbed on top row
if (rC(1) == -1)&&(~sC(1))
solution = gobeef(1,0,1,n); %straight over through top row
done = 1;
else %reflected up
beam(0,cC(1)+1,'high')
edgesol(2,cC(1)+1) = sC(1);
done = 0;
end
end

end

solution = solution + edgesol + cornsol;

function [solution] = sides(n)
%error('Still No Clean Edges!')
solution = zeros(n);

function [solution] = corners(n)
solution = zeros(n);
%top left
R = 2;
C = 2;
[r1,c1,s1] = beam(R,0);
[r2,c2,s2] = beam(0,C);
if (r1==R)&&(c2==C)
solution(1,1) =  min(s1,s2);
beam(1,0,'high');
elseif (r1==R)
solution(R+1,1) = s1;
beam(R+1,0,'high');
elseif (c2==C)
solution(1,C+1) = s2;
beam(0,C+1,'high');
end

%top right
R = -2;
C = n-1;
[r1,c1,s1] = beam(R,0);
[r2,c2,s2] = beam(0,C);
if (r1==R)&&(c2==C)
solution(1,n) =  min(s1,s2);
beam(0,-n,'high');
elseif (r1==R)
solution(R-1,1) = s1;
beam(R-1,0,'high');
elseif (c2==C)
solution(1,C-1) = s2;
beam(0,C-1,'high');
end

%bottom left
R = n-1;
C = -2;
[r1,c1,s1] = beam(R,0);
[r2,c2,s2] = beam(0,C);
if (r1==R)&&(c2==C)
solution(n,1) =  min(s1,s2);
beam(n,0,'high');
elseif (r1==R)
solution(R-1,1) = s1;
beam(R-1,0,'high');
elseif (c2==C)
solution(1,C-1) = s2;
beam(0,C-1,'high');
end

%bottom right
R = -n+1;
C = -n+1;
[r1,c1,s1] = beam(R,0);
[r2,c2,s2] = beam(0,C);
if (r1==R)&&(c2==C)
solution(n,n) =  min(s1,s2);
beam(-n,0,'high');
elseif (r1==R)
solution(R+1,n) = s1;
beam(R+1,0,'high');
elseif (c2==C)
solution(1,C+1) = s2;
beam(0,C+1,'high');
end

function [solution] = gobeef(R,C,tb,n) %tb=1 = 'top/left', tb=0 = 'bottom/right',
disp(R)
disp(C)
disp(tb)
solution = zeros(n);
if tb
if R
for i = 1:(n-R-1)
[r,c,s] = beam(R+i,0);
while (~(-r==(R+i))) %anything but came out otherside
if r==(R+i) %immediately reflected
solution(r+1,1)=s;
beam(0,1,'high');
else %must have been reflected up
solution(R+1,c+1)=s;
beam(0,c+1,'high');
end
[r,c,s] = beam(R+i,0); %destroyed one so keep going in same place!
end
end
else
for i = 1:(n-C-1)
[r,c,s] = beam(0,C+i);
while (~(-c==(C+i))) %anything but came out otherside
if c==(C+i) %immediately reflected
solution(1,c+1)=s;
beam(0,c+1,'high');
else %must have been reflected left
solution(r+1,C+1)=s;
beam(r+1,0,'high');
end
[r,c,s] = beam(0,C+i); %destroyed one so keep going in same place!
end
end
end
else
if R
for i = 1:(R-2)
[r,c,s] = beam(R-i,0);
while (~(-r==(R-i))) %anything but came out otherside
if r==(R-i) %immediately reflected
solution(r-1,1)=s;
beam(r-1,0,'high');
else %must have been reflected down
solution(R-1,-c+1)=s;
beam(0,-(-c+1),'high');
end
R-1
[r,c,s] = beam(R-i,0); %destroyed one so keep going in same place!
end
end
else
for i = 1:(C-2)
[r,c,s] = beam(0,C-i);
while (~(-c==(C-i))) %anything but came out otherside
if c==(C-i) %immediately reflected
solution(1,c-1)=s;
beam(0,c-1,'high');
else %must have been reflected right
solution(-r+1,C-1)=s;
beam(-(-r+1),0,'high');
end
[r,c,s] = beam(0,C-i); %destroyed one so keep going in same place!
end
end
end
end

```