Finish 2012-11-07 16:00:00 UTC

Some say that he likes the taste of mercury

by Magnus S

Status: Passed
Results: 295812 (cyc: 5, node: 189)
CPU Time: 0.853
Score: 295815.0
Submitted at: 2012-10-31 16:35:45 UTC
Scored at: 2012-11-01 14:21:51 UTC

Comments
Please login or create a profile.
Code
function xyOut = solver(a, xyIn, wts)

%Stupid first idea

xyOut = xyIn;
a = a.*(ones(length(wts),1)*wts);

previousIndex = 1;
a(:,1) = 0*a(:,1);
for k = 2:size(xyOut,1)
    easiesttomove=min(a(previousIndex,a(previousIndex,:)>0));
    if(isempty(easiesttomove))
        break;
    else
        currentIndex = find(a(previousIndex,:)==easiesttomove,1);
    end
    xyOut(currentIndex,:) = xyOut(previousIndex,:)+[1,0];
    while(size(unique(xyOut,'rows'),1)~=size(xyOut,1))
        xyOut(currentIndex,:) = xyOut(currentIndex,:)+[1,0];
    end
    previousIndex = currentIndex;
    a(:,currentIndex) = 0*a(:,currentIndex);
end
xyOut(previousIndex,:) = xyOut(previousIndex,:) +[0,1];
while(size(unique(xyOut,'rows'),1)~=size(xyOut,1))
    xyOut(previousIndex,:) = xyOut(previousIndex,:)-[1,0];
end

end