ID:45750
Title:Hello neighbour!
Author:Ulf S.
Date:2008-05-01 07:35:24
Score:32811.8031
Result:328096.00 (cyc: 3, node: 172)
CPU Time:0.2317
Status:Passed
Comments:Connect only neighboured pins of the same value.
Based on:none
Code:
function W = solver(B)

W = zeros(0,4);

[cLen, rLen] = size(B);

nodeMax = max(B(:));
nodeMin = min(B(:));

curNode = nodeMax;
while curNode ~= 0
    pins = find(B == curNode);
    for curPin = 1:length(pins) - 1
        wiring(pins(curPin), pins(curPin + 1));
    end
    curNode = curNode - 1;
end


    function wiring(iPinA, iPinB)
        rA = rFromI(iPinA);
        cA = cFromI(iPinA);
        rB = rFromI(iPinB);
        cB = cFromI(iPinB);
        
        d = iPinB - iPinA;
        if d == 1 || d == cLen
            W = [W; [rA cA rB cB]];
        end
        
    end



    function r = rFromI(i)
        r = mod((i-1),cLen) + 1;
    end

    function c = cFromI(i)
        c = floor((i-1) / cLen) + 1;
    end
        

end