Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
%%
feval(@assignin,'caller','score',625);
|
2 | Fail |
%%
dict={'avalanche'
'bluejackets'
'blackhawks'
'blues'
'bruins'
'canadiens'
'canucks'
'capitals'
'coyotes'
'devils'
'ducks'
'flames'
'flyers'
'hurricanes'
'islanders'
'jets'
'kings'
'lightning'
'mapleleafs'
'oilers'
'panthers'
'penguins'
'predators'
'rangers'
'redwings'
'sabres'
'senators'
'sharks'
'stars'
'wild'};
t1 = cputime;
H=criss_cross(dict)
fprintf('Elapsed Time %.2f\n',cputime-t1)
fprintf('size of H %i %i\n',size(H));
score=prod(size(H)); % if valid
% Perform Validation : words
a=H;
% Ned's
gridWords = {};
for i = 1:2
a = a';
for j = 1:size(a,1)
tk = regexp(a(j,:),'(\w\w+)','tokens');
gridWords = [gridWords tk];
end
end
dictFound = cell(length(gridWords),1);
for i = 1:length(gridWords)
dictFound{i} = gridWords{i}{1};
end
dictFound = sort(dictFound);
dictGiven = sort(dict);
assert(isequal(dictGiven,dictFound),sprintf('Invalid/Missing words'))
% Perform Validation: Connected
Achar=H;
m= (Achar-96);
m(m>0)=Inf;
% expand m and encircle with 0
[nr, nc]=size(m);
m=[zeros(nr,1) m zeros(nr,1)];
m=[zeros(1,nc+2); m; zeros(1,nc+2)];
nr=size(m,1);
off_vec=[-1 1 -nr nr];
% Initialize start location
ptr=find(m==Inf,1,'first');
curval=1;
m(ptr)=curval;
while ~isempty(ptr) % adjacent expansion search sequence
curval=curval+1;
Moff_vec=repmat(ptr,1,4)+repmat(off_vec,size(ptr,1),1);
m(Moff_vec)=min(curval*ones(size(Moff_vec)), m(Moff_vec));
ptr=find(m==curval);
end
invalid=any(m(:)==Inf); % Any unconnected from start point will be Inf
assert(~invalid,sprintf('Not fully connected'))
Hscore=numel(H);
feval(@assignin,'caller','score',Hscore);
Error: Invalid/Missing words
|
the fly, the train, the second train, and their Zeno's paradox
55 Solvers
33 Solvers
Parse string and identify specific string sequence in algebraic equation
44 Solvers
Solve Rubik's Cube - Up to Two Face Moves
4 Solvers
26 Solvers