Cody

# Problem 44208. Where's Waldo?

Solution 1872409

Submitted on 12 Jul 2019 by Casper
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));

rn = 3 2 cn = 1 3 checking base coordinate: 3 1 checkLocation N = 4 7,-3 direction 1 out of bounds checkLocation N = 4 7,1 direction 2 out of bounds checkLocation N = 4 7,5 direction 3 out of bounds checkLocation N = 4 3,-3 direction 4 out of bounds checkLocation N = 4 3,5 direction 5 !!!--->>> 5 found at 3,5 checkLocation N = 3 3,4 direction 5 !!!--->>> 4 found at 3,4 checkLocation N = 2 3,3 direction 5 !!!--->>> 3 found at 3,3 checkLocation N = 1 We are back to square one, so finished! checkLocation N = 4 -1,-3 direction 6 out of bounds checkLocation N = 4 -1,1 direction 7 out of bounds checkLocation N = 4 -1,5 direction 8 out of bounds checking base coordinate: 2 3 checkLocation N = 4 6,-1 direction 1 out of bounds checkLocation N = 4 6,3 direction 2 out of bounds checkLocation N = 4 6,7 direction 3 out of bounds checkLocation N = 4 2,-1 direction 4 out of bounds checkLocation N = 4 2,7 direction 5 out of bounds checkLocation N = 4 -2,-1 direction 6 out of bounds checkLocation N = 4 -2,3 direction 7 out of bounds checkLocation N = 4 -2,7 direction 8 out of bounds

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' rn = 1 3 2 cn = 1 3 5 checking base coordinate: 1 1 checkLocation N = 4 5,-3 direction 1 out of bounds checkLocation N = 4 5,1 direction 2 out of bounds checkLocation N = 4 5,5 direction 3 out of bounds checkLocation N = 4 1,-3 direction 4 out of bounds checkLocation N = 4 1,5 direction 5 number not found here checkLocation N = 4 -3,-3 direction 6 out of bounds checkLocation N = 4 -3,1 direction 7 out of bounds checkLocation N = 4 -3,5 direction 8 out of bounds checking base coordinate: 3 3 checkLocation N = 4 7,-1 direction 1 out of bounds checkLocation N = 4 7,3 direction 2 out of bounds checkLocation N = 4 7,7 direction 3 out of bounds checkLocation N = 4 3,-1 direction 4 out of bounds checkLocation N = 4 3,7 direction 5 out of bounds checkLocation N = 4 -1,-1 direction 6 out of bounds checkLocation N = 4 -1,3 direction 7 out of bounds checkLocation N = 4 -1,7 direction 8 out of bounds checking base coordinate: 2 5 checkLocation N = 4 6,1 direction 1 out of bounds checkLocation N = 4 6,5 direction 2 out of bounds checkLocation N = 4 6,9 direction 3 out of bounds checkLocation N = 4 2,1 direction 4 !!!--->>> 5 found at 2,1 checkLocation N = 3 2,2 direction 4 !!!--->>> 4 found at 2,2 checkLocation N = 2 2,3 direction 4 !!!--->>> 3 found at 2,3 checkLocation N = 1 We are back to square one, so finished! checkLocation N = 4 2,9 direction 5 out of bounds checkLocation N = 4 -2,1 direction 6 out of bounds checkLocation N = 4 -2,5 direction 7 out of bounds checkLocation N = 4 -2,9 direction 8 out of bounds

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

rn = 1 cn = 1 checking base coordinate: 1 1 checkLocation N = 4 5,-3 direction 1 out of bounds checkLocation N = 4 5,1 direction 2 number not found here checkLocation N = 4 5,5 direction 3 !!!--->>> 5 found at 5,5 checkLocation N = 3 4,4 direction 3 !!!--->>> 4 found at 4,4 checkLocation N = 2 3,3 direction 3 !!!--->>> 3 found at 3,3 checkLocation N = 1 We are back to square one, so finished! checkLocation N = 4 1,-3 direction 4 out of bounds checkLocation N = 4 1,5 direction 5 number not found here checkLocation N = 4 -3,-3 direction 6 out of bounds checkLocation N = 4 -3,1 direction 7 out of bounds checkLocation N = 4 -3,5 direction 8 out of bounds

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);