Finish 2011-04-20 12:00:00 UTC

xplor10xplt2

by Giovanni Granato

Status: Passed
Results: 10804711 (cyc: 10, node: 378)
CPU Time: 160.047
Score: 56372.7
Submitted at: 2011-04-14 09:47:38 UTC
Scored at: 2011-04-14 10:08:29 UTC

Current Rank: 1836th (Highest: 151st )
Based on: xplr10xplt2 (diff)

Comments
Please login or create a profile.
Code
function board = solver(words, weights, n, penalty)
board = zeros(n);c=1;ct=10*n;
while (c<ct) 
[~,wn]=max(weights);
if ~isempty(words{wn})
bd=board;w=words{wn};pty=penalty;wt=weights(wn);
lw=length(w);ok=0;
bdw=[zeros(1,n);bd(1:end-1,:)];
bup=[bd(2:end,:);zeros(1,n)];
blf=[bd(:,2:end),zeros(n,1)];
brt=[zeros(n,1),bd(:,1:end-1)];
PZ=bd+bdw+bup+blf+brt;KZ=bd;FA=ones(n); 
for L=1:round(n/2)
if rand>0.5
tt=[ceil(rand*n) ceil(rand*(n-lw+1))];
NB=zeros(n);NB(tt(1),tt(2):tt(2)+lw-1)=w;   
else
tt=[ceil(rand*(n-lw+1)) ceil(rand*n)];
NB=zeros(n);NB(tt(1):tt(1)+lw-1,tt(2))=w;  
end
if sum(sum(KZ&NB))
I=find(KZ&NB);
if KZ(I)==NB(I)
FA(I)=2;
else
continue    
end
end
if sum(sum(PZ&NB))*pty-wt>0
continue
else
board=(NB+bd)./FA;
ok=1;break;
end
end
if ~ok
weights(wn)=-1;
end    
end
if ok
words{wn}=[];
weights(wn)=-1;
end
c=c+1;
end