Finish 2011-04-20 12:00:00 UTC

Abandoned places

by Andre Fioravanti

Status: Passed
Results: 8448066 (cyc: 5, node: 155)
CPU Time: 0.463
Score: 21120.2
Submitted at: 2011-04-13 17:11:29 UTC
Scored at: 2011-04-13 17:13:41 UTC

Current Rank: 1541st (Highest: 1st )

Comments
Please login or create a profile.
Code
function board = solver(words, weights, n, penalty)

board = zeros(n);

ppl = zeros(size(weights));
for i = 1:length(ppl)
    ppl(i) = weights(i) ./ length(words{i});
end

[~,idx] = sort(ppl,2,'descend');

epl = n * ones(1,n);

it = 1;
for i=1:2:n
    pt = 1;
    cont = 1;
    while(cont)
        word = words{idx(it)};
        if length(word) <= epl(i)
            board(i,pt:(pt+length(word)-1)) = word;
            pt = pt + length(word) + 1;
            epl(i) = epl(i) - length(word) - 1;
            it = it+1;
        else
            cont = 0;
        end
    end
end


end