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

WordList 02

by Robert Macrae

Status: Passed
Results: 7943530 (cyc: 4, node: 141)
CPU Time: 0.59
Score: 19858.9
Submitted at: 2011-04-13 18:10:54 UTC
Scored at: 2011-04-13 18:12:27 UTC

Current Rank: 1368th (Highest: 1st )

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

% Crossword Solver

% WordList02 -- all rows
% results: 6991690.00
% time: 0.27

% WordList01 -- alternate rows
% results: 7494085.00
% time: 0.11


board = zeros(n);

[~,WordLen] = cellfun(@size,words);         % Length of each word
WordPriority = weights ./ (WordLen+1);      % Guess at priority
[WordPriority,Index] = sort(WordPriority,'descend');  % Find words in priority order
WordLen = WordLen(Index);
words = words(Index);                       % ... and sort words to match
Used = false(size(WordLen));

Next = 1;
for Row = 1:1:n     % Start by filling alternate rows
    Col = 1;
    while Col < n 
        if n-Col+1 >= WordLen(Next)             % Check!
            board(Row,Col:Col+WordLen(Next)-1) = words{Next};
            Used(Next) = true;                  % Not currently used
            Next = Next+1;
            Col = Col+WordLen(Next)+1;
        else
            Col = n+1;
            % For now ignore possibility of fitting in short words
            % at end
        end
    end
end    
 
end