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

Some say that he lives in a hollowed out oak tree

by Magnus S

Status: Passed
Results: 295476 (cyc: 5, node: 198)
CPU Time: 0.86
Score: 295480.0
Submitted at: 2012-11-01 12:07:27 UTC
Scored at: 2012-11-01 18:54:07 UTC

Current Rank: 1720th (Highest: 38th )
Based on: Some say that he likes the taste of mercury (diff)

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);

zigzag = 1;
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,zigzag];
    while(size(unique(xyOut,'rows'),1)~=size(xyOut,1))
        xyOut(currentIndex,:) = xyOut(currentIndex,:)+[1,0];
    end
    previousIndex = currentIndex;
    a(:,currentIndex) = 0*a(:,currentIndex);
    zigzag = -zigzag;
end
xyOut(previousIndex,:) = xyOut(previousIndex,:) +[0,1];
while(size(unique(xyOut,'rows'),1)~=size(xyOut,1))
    xyOut(previousIndex,:) = xyOut(previousIndex,:)-[1,0];
end

end