Cody

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

Here's what your picture looked like: YEekJkdgElckvf oofCqmgcROQHlb cZvYCVGTQnhHoq KOdLAWHPKZWNSU qoujNVisIhunLL JnyHxpYDMfcvje NtAdzdZftUvPGn sZcCoPLVthWASC rn = 4 4 8 cn = 6 11 11 checking base coordinate: 4 6 checkLocation N = 4 8,2 direction 1 number not found here checkLocation N = 4 8,6 direction 2 number not found here checkLocation N = 4 8,10 direction 3 number not found here checkLocation N = 4 4,2 direction 4 !!!--->>> 5 found at 4,2 checkLocation N = 3 4,3 direction 4 !!!--->>> 4 found at 4,3 checkLocation N = 2 4,4 direction 4 !!!--->>> 3 found at 4,4 checkLocation N = 1 We are back to square one, so finished! checkLocation N = 4 4,10 direction 5 number not found here checkLocation N = 4 0,2 direction 6 out of bounds checkLocation N = 4 0,6 direction 7 out of bounds checkLocation N = 4 0,10 direction 8 out of bounds checking base coordinate: 4 11 checkLocation N = 4 8,7 direction 1 number not found here checkLocation N = 4 8,11 direction 2 number not found here checkLocation N = 4 8,15 direction 3 out of bounds checkLocation N = 4 4,7 direction 4 number not found here checkLocation N = 4 4,15 direction 5 out of bounds checkLocation N = 4 0,7 direction 6 out of bounds checkLocation N = 4 0,11 direction 7 out of bounds checkLocation N = 4 0,15 direction 8 out of bounds checking base coordinate: 8 11 checkLocation N = 4 12,7 direction 1 out of bounds checkLocation N = 4 12,11 direction 2 out of bounds checkLocation N = 4 12,15 direction 3 out of bounds checkLocation N = 4 8,7 direction 4 number not found here checkLocation N = 4 8,15 direction 5 out of bounds checkLocation N = 4 4,7 direction 6 number not found here checkLocation N = 4 4,11 direction 7 number not found here checkLocation N = 4 4,15 direction 8 out of bounds

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: iaIyrgmPEkndKJBCzKE EOaJPTDhwHplrRysNSj dJqSBQvzuWRpeNxSgis ntsxOYyXeoqKRvECVpa CDDVvGvMmjwPTUQumiS GAEZNmlZahZpNfpbqPS WMVHYcovJLBCzbFiEvw oDsNttadeswQyvMCAjd LexlInCDlqhXaomgkIG dQQCxmQxrADycuUPEdn KimfMtQaaZWYKlUkTrc YijilMXqRhcaYZZTuqD AciOnprCnawrFspJRXU QBwpRjRFPRaVsjgzDCX YZtLzVZIXwSPINjFZms ChWUOFUiHubnRluQNNH HCXofeRjGDEGDFcBCBn PRbrwWcZbVzkoYHOVFW rn = 7 14 16 18 18 2 3 15 5 8 11 13 7 18 cn = 1 3 3 5 6 9 10 10 11 11 11 11 19 19 checking base coordinate: 7 1 checkLocation N = 4 11,-3 direction 1 out of bounds checkLocation N = 4 11,1 direction 2 number not found here checkLocation N = 4 11,5 direction 3 number not found here checkLocation N = 4 7,-3 direction 4 out of bounds checkLocation N = 4 7,5 direction 5 number not found here checkLocation N = 4 3,-3 direction 6 out of bounds checkLocation N = 4 3,1 direction 7 number not found here checkLocation N = 4 3,5 direction 8 number not found here checking base coordinate: 14 3 checkLocation N = 4 18,-1 direction 1 out of bounds checkLocation N = 4 18,3 direction 2 number not found here checkLocation N = 4 18,7 direction 3 number not found here checkLocation N = 4 14,-1 direction 4 out of bounds checkLocation N = 4 14,7 direction 5 number not found here checkLocation N = 4 10,-1 direction 6 out of bounds checkLocation N = 4 10,3 direction 7 number not found here checkLocation N = 4 10,7 direction 8 number not found here checking base coordinate: 16 3 checkLocation N = 4 20,-1 direction 1 out of bounds checkLocation N = 4 20,3 direction 2 out of bounds checkLocation N = 4 20,7 direction 3 out of bounds checkLocation N = 4 16,-1 direction 4 out of bounds checkLocation N = 4 16,7 direction 5 number not found here checkLocation N = 4 12,-1 direction 6 out of bounds checkLocation N = 4 12,3 direction 7 number not found here checkLocation N = 4 12,7 direction 8 number not found here checking base coordinate: 18 5 checkLocation N = 4 22,1 direction 1 out of bounds checkLocation N = 4 22,5 direction 2 out of bounds checkLocation N = 4 22,9 direction 3 out of bounds checkLocation N = 4 18,1 direction 4 number not found here checkLocation N = 4 18,9 direction 5 number not found here checkLocation N = 4 14,1 direction 6 number not found here checkLocation N = 4 14,5 direction 7 number not found here checkLocation N = 4 14,9 direction 8 number not found here checking base coordinate: 18 6 checkLocation N = 4 22,2 direction 1 out of bounds checkLocation N = 4 22,6 direction 2 out of bounds checkLocation N = 4 22,10 direction 3 out of bounds checkLocation N = 4 18,2 direction 4 number not found here checkLocation N = 4 18,10 direction 5 number not found here checkLocation N = 4 14,2 direction 6 number not found here checkLocation N = 4 14,6 direction 7 number not found here checkLocation N = 4 14,10 direction 8 number not found here checking base coordinate: 2 9 checkLocation N = 4 6,5 direction 1 number not found here checkLocation N = 4 6,9 direction 2 number not found here checkLocation N = 4 6,13 direction 3 number not found here checkLocation N = 4 2,5 direction 4 number not found here checkLocation N = 4 2,13 direction 5 number not found here checkLocation N = 4 -2,5 direction 6 out of bounds checkLocation N = 4 -2,9 direction 7 out of bounds checkLocation N = 4 -2,13 direction 8 out of bounds checking base coordinate: 3 10 checkLocation N = 4 7,6 direction 1 number not found here checkLocation N = 4 7,10 direction 2 number not found here checkLocation N = 4 7,14 direction 3 number not found here checkLocation N = 4 3,6 direction 4 number not found here checkLocation N = 4 3,14 direction 5 number not found here checkLocation N = 4 -1,6 direction 6 out of bounds checkLocation N = 4 -1,10 direction 7 out of bounds checkLocation N = 4 -1,14 direction 8 out of bounds checking base coordinate: 15 10 checkLocation N = 4 19,6 direction 1 out of bounds checkLocation N = 4 19,10 direction 2 out of bounds checkLocation N = 4 19,14 direction 3 out of bounds checkLocation N = 4 15,6 direction 4 number not found here checkLocation N = 4 15,14 direction 5 number not found here checkLocation N = 4 11,6 direction 6 number not found here checkLocation N = 4 11,10 direction 7 number not found here checkLocation N = 4 11,14 direction 8 number not found here checking base coordinate: 5 11 checkLocation N = 4 9,7 direction 1 number not found here checkLocation N = 4 9,11 direction 2 number not found here checkLocation N = 4 9,15 direction 3 number not found here checkLocation N = 4 5,7 direction 4 number not found here checkLocation N = 4 5,15 direction 5 number not found here checkLocation N = 4 1,7 direction 6 number not found here checkLocation N = 4 1,11 direction 7 number not found here checkLocation N = 4 1,15 direction 8 number not found here checking base coordinate: 8 11 checkLocation N = 4 12,7 direction 1 number not found here checkLocation N = 4 12,11 direction 2 number not found here checkLocation N = 4 12,15 direction 3 number not found here checkLocation N = 4 8,7 direction 4 number not found here checkLocation N = 4 8,15 direction 5 number not found here checkLocation N = 4 4,7 direction 6 number not found here checkLocation N = 4 4,11 direction 7 number not found here checkLocation N = 4 4,15 direction 8 number not found here checking base coordinate: 11 11 checkLocation N = 4 15,7 direction 1 number not found here checkLocation N = 4 15,11 direction 2 number not found here checkLocation N = 4 15,15 direction 3 number not found here checkLocation N = 4 11,7 direction 4 number not found here checkLocation N = 4 11,15 direction 5 number not found here checkLocation N = 4 7,7 direction 6 !!!--->>> 5 found at 7,7 checkLocation N = 3 8,8 direction 6 !!!--->>> 4 found at 8,8 checkLocation N = 2 9,9 direction 6 !!!--->>> 3 found at 9,9 checkLocation N = 1 We are back to square one, so finished! checkLocation N = 4 7,11 direction 7 number not found here checkLocation N = 4 7,15 direction 8 number not found here checking base coordinate: 13 11 checkLocation N = 4 17,7 direction 1 number not found here checkLocation N = 4 17,11 direction 2 number not found here checkLocation N = 4 17,15 direction 3 number not found here checkLocation N = 4 13,7 direction 4 number not found here checkLocation N = 4 13,15 direction 5 number not found here checkLocation N = 4 9,7 direction 6 number not found here checkLocation N = 4 9,11 direction 7 number not found here checkLocation N = 4 9,15 direction 8 number not found here checking base coordinate: 7 19 checkLocation N = 4 11,15 direction 1 number not found here checkLocation N = 4 11,19 direction 2 number not found here checkLocation N = 4 11,23 direction 3 out of bounds checkLocation N = 4 7,15 direction 4 number not found here checkLocation N = 4 7,23 direction 5 out of bounds checkLocation N = 4 3,15 direction 6 number not found here checkLocation N = 4 3,19 direction 7 number not found here checkLocation N = 4 3,23 direction 8 out of bounds checking base coordinate: 18 19 checkLocation N = 4 22,15 direction 1 out of bounds checkLocation N = 4 22,19 direction 2 out of bounds checkLocation N = 4 22,23 direction 3 out of bounds checkLocation N = 4 18,15 direction 4 number not found here checkLocation N = 4 18,23 direction 5 out of bounds checkLocation N = 4 14,15 direction 6 number not found here checkLocation N = 4 14,19 direction 7 number not found here checkLocation N = 4 14,23 direction 8 out of bounds