Finish 2008-05-07 12:00:00 UTC

farmboy

by Corey Hahn

Status: Passed
Results: 323664.00 (cyc: 5, node: 434)
CPU Time: 0.4837
Score: 32368.9
Submitted at: 2008-05-01 02:42:37 UTC
Scored at: 2008-05-01 02:43:53 UTC

Current Rank: 3505th

Comments
Please login or create a profile.
Code
function W = solver(B)
W = zeros(0,4);

a1 = unique(nonzeros(B));
a1 = a1(:);
[ro co] = size(B);

b1 = linksgen(ro, co);

%% wipe out orphan pins
for n = a1'
	n	;
    [a2 a3] = find(B == n);
	[a2 a3];
	if (length(a2) == 1)
		a1 = setdiff(a1, n);
		a10 = sub2ind ([ro co], a2, a3);
		b1(find(b1(:,1) == a10), :) = 0; 
		b1(find(b1(:,2) == a10), :) = 0;
		%%disp(['take out ' num2str(n) ' at ' num2str(a10)])
	end
end
b1hash = b1(:,1)*1000+b1(:,2);
b1hash = unique(b1hash);
if (b1hash(1) == 0)
	b1hash = b1hash(2:end);
end


%% wipe out wires with touching differnt pins
[a30 a31 a32] = find(B);

a33 = repmat(a30 + i*a31, 1, length(a30));

a34 = a33.';

a35 = triu(a33-a34);

a36 = real(a35).^2+imag(a35).^2;

[a37 a38] = find(a36 == 1);

a39 = find(a32(a37)-a32(a38) == 0); %% these need to be connected

%% good
if (length(a39 ~= 0))
	W = [a30(a37(a39)) a31(a37(a39)) a30(a38(a39)) a31(a38(a39))];
end



return

function k2 = linksgen(r, c)
t = c;
c = r;
r = t;

s1 = 1.002:1.001:((c-1)+c/1000);
s1 = repmat(s1, r, 1);
s2 = repmat(c + c/1000, r, c-1);
s2(1,:) = 0;
s2 = cumsum(s2, 1);
k1 = s1+s2;
k1 = k1(:);

s1 = 1+((c+1)/1000):c+c/1000:c*(r-1);;
s1 = repmat(s1, c, 1);
s2 = repmat(1 + 1/1000, c, r-1);
s2(1,:) = 0;
s2 = cumsum(s2, 1);
s1 = s1+s2;
k1 = [k1; s1(:)];

k2 = [round(k1) round((k1-round(k1))*1000)];
k1 = k2;
return