Cody

# Problem 44208. Where's Waldo?

Solution 1197168

Submitted on 25 May 2017 by Binbin Qi
• Size: 35
• This is the leading solution.
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));

ans = Columns 1 through 30 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Columns 31 through 45 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11

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' ans = Columns 1 through 30 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Columns 31 through 45 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11

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

ans = Columns 1 through 30 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Columns 31 through 45 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11

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: wlYjACYPQiQ cHuYcAmXCco QCRVSrWVzQZ QmqAosXCdtM psdkwczIhRC tDlexbxUJzw aXWalDoDdLE ans = Columns 1 through 30 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Columns 31 through 45 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11