Cody

# Problem 44208. Where's Waldo?

Solution 1710631

Submitted on 20 Jan 2019 by William
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
picture1 = ['QGxOe' 'dMWdg' 'Waldo']; waldoSub = [3 1; 3 2; 3 3; 3 4; 3 5]; assert(isequal(findWaldo(picture1),waldoSub));

2   Pass
picture2 = ['WLvJC' 'oDlaw' 'dMWdg'] waldoSub = [2 5; 2 4; 2 3; 2 2; 2 1]; assert(isequal(findWaldo(picture2),waldoSub));

picture2 = 3×5 char array 'WLvJC' 'oDlaw' 'dMWdg'

3   Pass
picture3 =['WFBlS' 'DAlzQ' 'pjLTo' 'xnaDF' 'YgYRO']; waldoSub = [1 1; 2 2; 3 3; 4 4; 5 5]; assert(isequal(findWaldo(picture3),waldoSub));

4   Pass
clear all; waldoStr = 'waldo'; szStr=numel(waldoStr); % randomly reverse waldo if(randi(2)-1) waldoStr = fliplr(waldoStr); end % randomly change case of waldo letters for i=1:szStr if(randi(2)-1) waldoStr(i) = upper(waldoStr(i)); end end % create a picture sized randomly picture ([10..15] x [10..15]) numRows=randi(10)+szStr; numCols=randi(10)+szStr; % containing a mixture of upper and lower case letters offset = ['A','a']-1; picture = char(randi(26,numRows,numCols)+offset(randi(2,numRows,numCols))); % pick a random direction for writing waldo. % Remember it could be 'odlaw' at this point so it is not a % problem that we are not considering reverse order here rowDir = randi(2)-1; colDir = 1-rowDir; % Get a random spot on the board to place waldo, that is within bounds of % the board if(rowDir) startR = randi(numRows-szStr); else startR = randi(numRows); end if(colDir) startC = randi(numCols-szStr); else startC = randi(numCols); end waldoSub = repmat([startR, startC],szStr,1)+... cumsum([0, 0; repmat([rowDir,colDir],szStr-1,1)]); waldoInd = sub2ind([numRows,numCols],waldoSub(:,1),waldoSub(:,2))'; picture(waldoInd)=waldoStr; % Display the board so people can at least see what they were dealing % with and, per chance, complain that Waldo is not in here. fprintf(1,'Here''s what your picture looked like:\n'); disp(picture); % need to give somewhat of a challenge here ... clear waldoSub waldoInd waldoStr startR startC rowDir colDir offset szStr; % It could be that a waldo was randomly created in the board somewhere else so let's % just check against the string waldo itself to be fair to our test takers try waldoSub = findWaldo(picture); waldoInd = sub2ind([numRows,numCols],waldoSub(:,1),waldoSub(:,2))'; didPass = strcmpi(picture(waldoInd),'waldo'); catch me didPass = false; end assert(didPass);

Here's what your picture looked like: dgCkRRsZdIxYtb YizSXVYvjjeUet FzaBvWsifkfdJz prrWeKlnpwQJkU JGrarWfrHJSGUp rOklFzfmqTsAHu gTUdNKkkHEsLvP vkMOylXnucQFym rpCqtSwGhZrIKP

5   Pass
% Test 4 clear all; waldoStr = 'waldo'; szStr=numel(waldoStr); % randomly change case of waldo letters for i=1:szStr if(randi(2)-1) waldoStr(i) = upper(waldoStr(i)); end end % create a picture sized randomly picture ([10..15] x [10..15]) numRows=randi(15)+szStr; numCols=randi(15)+szStr; % containing a mixture of upper and lower case letters offset = ['A','a']-1; picture = char(randi(26,numRows,numCols)+offset(randi(2,numRows,numCols))); % pick a random direction for writing waldo. % Remember it could be 'odlaw' at this point so it is not a % problem that we are not considering reverse order here colDir = randi(3)-2; if(~colDir) rowDir = randi(2)*2-3; %cos(pi*randi(2)); else rowDir = randi(3)-2; end % Get a random spot on the board to place waldo, that is within bounds of % the board if(rowDir>0) startR = randi(numRows-szStr); elseif(rowDir<0) startR = randi(numRows-szStr)+szStr; else startR = randi(numRows); end if(colDir>0) startC = randi(numCols-szStr); elseif(colDir<0) startC = randi(numCols-szStr)+szStr; else startC = randi(numCols); end waldoSub = repmat([startR, startC],szStr,1)+... cumsum([0, 0; repmat([rowDir,colDir],szStr-1,1)]); waldoInd = sub2ind([numRows,numCols],waldoSub(:,1),waldoSub(:,2))'; picture(waldoInd)=waldoStr; % Display the board so people can at least see what they were dealing % with and, per chance, complain that Waldo is not in here. fprintf(1,'Here''s what your picture looked like:\n'); disp(picture); % need to give somewhat of a challenge here ... clear waldoSub waldoInd waldoStr startR startC rowDir colDir offset szStr; % It could be that a waldo was randomly created in the board somewhere else so let's % just check against the string waldo itself to be fair to our test takers try waldoSub = findWaldo(picture); waldoInd = sub2ind([numRows,numCols],waldoSub(:,1),waldoSub(:,2))'; didPass = strcmpi(picture(waldoInd),'waldo'); catch me didPass = false; end assert(didPass);

Here's what your picture looked like: FEJgqjYvI iQgZxolCI fsrEUahjX dVCQHPScc rOBfodLAW VUEIopZtX MeoWozVlg PnazuNXSc xpJLPqYYH uPsrVKvvd zwEkMfpfA