% checks wether the connection should come with plus or minus, which is
% dependent on how it must be sorted. This function needs both the sorted
% and the one which is not sorted and compares them. The sign is determined
% from if the new spState is moved an even or odd number of steps.

function sign = signedConnection(stateSorted,activeMpState)
lastind = 0;
firstind = 0;
for i = 1:length(stateSorted)
    if stateSorted(i) ~= activeMpState(i)
        firstind = i;
        break
    end
end

for i = length(stateSorted):-1:1
    if stateSorted(i) ~= activeMpState(i)
        lastind = i;
        break
    end
end

sign = (-1)^(lastind-firstind);

end