2011-11-09 12:00:00 UTC

Vine variants

by Victoria

Status: Passed
Results: 76120336 (cyc: 11, node: 458)
CPU Time: 175.453
Score: 29653900.0
Submitted at: 2011-11-03 15:08:36 UTC
Scored at: 2011-11-03 15:15:39 UTC

Current Rank: 1622nd (Highest: 184th )
Based on: Venti (diff)
Basis for: Vines in the dark (diff)
Basis for: Vines 6 (diff)
Basis for: Vines 7 (diff)

Code
```function [moves, vine] = solver(board, limit)

% Victoria's solver

moves = [];
N = size(board);
Q = floor(N(1)*N(2)/8);
vineVariants = cell(Q,1);
R = zeros(Q,1);
[~,I]=sort(board(:),'descend');
for i=1:Q
vine = I(i);
Continue = true;
while Continue
Check = setdiff(neighbours(vine(1)),vine);
Check = Check(board(Check)<=board(vine(1)));
if ~isempty(Check)
[~,PreviousInCheck] = max(board(Check));
vine = [Check(PreviousInCheck) vine];
else
Continue = false;
end
end
vineVariants{i} = vine;
R(i) = result(board,board,vineVariants{i});
end
[~,S] = min(R);
vine = vineVariants{S};

function LN = neighbours(L)
if L == 1
LN = [2 N(1)+1];
elseif L == N(1)
LN = [2*N(1) N(1)-1];
elseif L == N(1)*N(2) - N(1) + 1
LN = [N(1)*N(2)-N(1)+2 N(1)*N(2)-2*N(1)+1];
elseif L == N(1)*N(2)
LN = [N(1)*N(2)-1 N(1)*N(2)-N(1)];
elseif L >= 2 && L <= N(1)
LN = [L-1 L+N(1) L+1];
elseif L >= N(1)*N(2) - N(1) && L <= N(1)*N(2) - 1
LN = [L-1 L-N(1) L+1];
elseif mod(L,N(1)) == 1
LN = [L-N(1) L+1 L+N(1)];
elseif mod(L,N(1)) == 0
LN = [L-N(1) L-1 L+N(1)];
else
LN = [L-1 L+N(1) L+1 L-N(1)];
end
end
function R = result(board,modified_board,vine)
R = sum(board(:)) - sum(modified_board(vine));
end
end```