2011-04-20 12:00:00 UTC

# 1st try

by Thobias

Status: Passed
Results: 8583344 (cyc: 9, node: 206)
CPU Time: 1.163
Score: 21458.5
Submitted at: 2011-04-13 22:13:22 UTC
Scored at: 2011-04-13 22:16:49 UTC

Current Rank: 1567th (Highest: 26th )
Basis for: 2nd try (diff)

Thobias
13 Apr 2011
This is not a good way of doing it...
Code
function board = solver(words, weights, n, penalty)

% Sample solver

% Copyright 2011 The MathWorks, Inc.

board = zeros(n);

% [weights weightsInds] = sort(weights,2,'descend');

wl = cellfun(@length,words);
[wl wordInds] = sort(wl,2,'ascend');

k = 1;
indInd = 1;
maxW = length(weights);
while k <= n
l = 1;
while l < n
if k ~= 1
if n-l > wl(indInd)
if sum(board(k-1,l:l+wl(indInd)-1)) == 0
board(k,l:l+wl(indInd)-1) = words{wordInds(indInd)};

l = l + wl(indInd)+1;
indInd = indInd + 1;
else
l = l+1;
end
else
break
end
else
if n-l > wl(indInd)
board(k,l:l+wl(indInd)-1) = words{wordInds(indInd)};

l = l + wl(indInd)+1;
indInd = indInd + 1;
else
break
end
end

if indInd - 1 == maxW
break;
end
end

k = k+1;

if indInd - 1 == maxW
break;
end
end

end