Cody

Solution 189578

Submitted on 11 Jan 2013 by Aurelien Queffurust
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
%% assignin('caller','score',300); a.words0={'BUZZ','COZY','DOZE','FUZZ','GAZE','HAZE','JAZZ','LAZY','SIZE','ZERO','ZONE'}; a.e=0; for n=randperm(numel(a.words0)) a.i=n; a.words=a.words0; a.n=n; for m=1:100, a.m=m; assignin('caller','a',a); letter=hangman(a.words); letter=char(letter(1)); a=evalin('caller','a'); m=a.m; fprintf('Target word %s; Step %d; Word list %s; Guess %c\n',a.words{a.i},a.m,sprintf('%s ',a.words{:}),letter); matchedletters=a.words{a.i}==letter; if ~any(matchedletters), a.e=a.e+1; end matchedwords=find(cellfun(@(x)isequal(matchedletters,x==letter),a.words)); a.i=find(matchedwords==a.i); a.words=regexprep(a.words(matchedwords),letter,''); nonemptywords=find(cellfun('length',a.words)>0); a.i=find(nonemptywords==a.i); if isempty(a.i), break; end end if ~isempty(a.i), error(sprintf('algorithm did not guess word after 100 steps. Last message: Target word %s; Step %d; Word list %s; Guessed letter %c\n',a.words{a.i},a.m,sprintf('%s ',a.words{:}),letter)); end n=a.n; end a.e=a.e/numel(a.words0); fprintf('Average number of errors per word %f\n',a.e); assert(a.e<5); assignin('caller','score',evalin('caller','score')-100+round(a.e/5*100));
letter = 90 Target word FUZZ; Step 1; Word list BUZZ COZY DOZE FUZZ GAZE HAZE JAZZ LAZY SIZE ZERO ZONE ; Guess Z letter = 85 Target word FU; Step 2; Word list BU FU JA ; Guess U letter = 66 Target word F; Step 3; Word list B F ; Guess B letter = 70 Target word F; Step 4; Word list F ; Guess F letter = 90 Target word DOZE; Step 1; Word list BUZZ COZY DOZE FUZZ GAZE HAZE JAZZ LAZY SIZE ZERO ZONE ; Guess Z letter = 69 Target word DOE; Step 2; Word list COY DOE GAE HAE LAY SIE ; Guess E letter = 65 Target word DO; Step 3; Word list DO GA HA SI ; Guess A letter = 68 Target word DO; Step 4; Word list DO SI ; Guess D letter = 79 Target word O; Step 5; Word list O ; Guess O letter = 90 Target word BUZZ; Step 1; Word list BUZZ COZY DOZE FUZZ GAZE HAZE JAZZ LAZY SIZE ZERO ZONE ; Guess Z letter = 85 Target word BU; Step 2; Word list BU FU JA ; Guess U letter = 66 Target word B; Step 3; Word list B F ; Guess B letter = 90 Target word JAZZ; Step 1; Word list BUZZ COZY DOZE FUZZ GAZE HAZE JAZZ LAZY SIZE ZERO ZONE ; Guess Z letter = 85 Target word JA; Step 2; Word list BU FU JA ; Guess U letter = 65 Target word JA; Step 3; Word list JA ; Guess A letter = 74 Target word J; Step 4; Word list J ; Guess J letter = 90 Target word ZERO; Step 1; Word list BUZZ COZY DOZE FUZZ GAZE HAZE JAZZ LAZY SIZE ZERO ZONE ; Guess Z letter = 69 Target word ERO; Step 2; Word list ERO ONE ; Guess E letter = 79 Target word RO; Step 3; Word list RO ; Guess O letter = 82 Target word R; Step 4; Word list R ; Guess R letter = 90 Target word GAZE; Step 1; Word list BUZZ COZY DOZE FUZZ GAZE HAZE JAZZ LAZY SIZE ZERO ZONE ; Guess Z letter = 69 Target word GAE; Step 2; Word list COY DOE GAE HAE LAY SIE ; Guess E letter = 65 Target word GA; Step 3; Word list DO GA HA SI ; Guess A letter = 71 Target word G; Step 4; Word list G H ; Guess G letter = 90 Target word HAZE; Step 1; Word list BUZZ COZY DOZE FUZZ GAZE HAZE JAZZ LAZY SIZE ZERO ZONE ; Guess Z letter = 69 Target word HAE; Step 2; Word list COY DOE GAE HAE LAY SIE ; Guess E letter = 65 Target word HA; Step 3; Word list DO GA HA SI ; Guess A letter = 71 Target word H; Step 4; Word list G H ; Guess G letter = 72 Target word H; Step 5; Word list H ; Guess H letter = 90 Target word COZY; Step 1; Word list BUZZ COZY DOZE FUZZ GAZE HAZE JAZZ LAZY SIZE ZERO ZONE ; Guess Z letter = 69 Target word COY; Step 2; Word list COY DOE GAE HAE LAY SIE ; Guess E letter = 89 Target word COY; Step 3; Word list COY LAY ; Guess Y letter = 65 Target word CO; Step 4; Word list CO LA ; Guess A letter = 67 Target word CO; Step 5; Word list CO ; Guess C letter = 79 Target word O; Step 6; Word list O ; Guess O letter = 90 Target word SIZE; Step 1; Word list BUZZ COZY DOZE FUZZ GAZE HAZE JAZZ LAZY SIZE ZERO ZONE ; Guess Z letter = 69 Target word SIE; Step 2; Word list COY DOE GAE HAE LAY SIE ; Guess E letter = 65 Target word SI; Step 3; Word list DO GA HA SI ; Guess A letter = 68 Target word SI; Step 4; Word list DO SI ; Guess D letter = 73 Target word SI; Step 5; Word list SI ; Guess I letter = 83 Target word S; Step 6; Word list S ; Guess S letter = 90 Target word ZONE; Step 1; Word list BUZZ COZY DOZE FUZZ GAZE HAZE JAZZ LAZY SIZE ZERO ZONE ; Guess Z letter = 69 Target word ONE; Step 2; Word list ERO ONE ; Guess E letter = 78 Target word ON; Step 3; Word list ON ; Guess N letter = 79 Target word O; Step 4; Word list O ; Guess O letter = 90 Target word LAZY; Step 1; Word list BUZZ COZY DOZE FUZZ GAZE HAZE JAZZ LAZY SIZE ZERO ZONE ; Guess Z letter = 69 Target word LAY; Step 2; Word list COY DOE GAE HAE LAY SIE ; Guess E letter = 89 Target word LAY; Step 3; Word list COY LAY ; Guess Y letter = 65 Target word LA; Step 4; Word list CO LA ; Guess A letter = 76 Target word L; Step 5; Word list L ; Guess L Average number of errors per word 0.818182
2   Pass
%% rng default; a.words0=cellstr(unique(char('A'+ceil(26*rand([200,3]).^2)-1),'rows'))'; a.e=0; for n=randperm(numel(a.words0)) a.i=n; a.words=a.words0; a.n=n; for m=1:100, a.m=m; assignin('caller','a',a); letter=hangman(a.words); letter=char(letter(1)); a=evalin('caller','a'); m=a.m; matchedletters=a.words{a.i}==letter; if ~any(matchedletters), a.e=a.e+1; end matchedwords=find(cellfun(@(x)isequal(matchedletters,x==letter),a.words)); a.i=find(matchedwords==a.i); a.words=regexprep(a.words(matchedwords),letter,''); nonemptywords=find(cellfun('length',a.words)>0); a.i=find(nonemptywords==a.i); if isempty(a.i), break; end end if ~isempty(a.i), error(sprintf('algorithm did not guess word after 100 steps. Last message: Target word %s; Step %d; Word list %s; Guessed letter %c\n',a.words{a.i},a.m,sprintf('%s ',a.words{:}),letter)); end n=a.n; end a.e=a.e/numel(a.words0); fprintf('Average number of errors per word %f\n',a.e); assert(a.e<5); assignin('caller','score',evalin('caller','score')-100+round(a.e/5*100));
letter = 65 letter = 66 letter = 67 letter = 69 letter = 70 letter = 71 letter = 72 letter = 73 letter = 80 letter = 65 letter = 68 letter = 67 letter = 82 letter = 86 letter = 65 letter = 68 letter = 73 letter = 80 letter = 65 letter = 69 letter = 66 letter = 72 letter = 68 letter = 82 letter = 65 letter = 66 letter = 70 letter = 67 letter = 68 letter = 80 letter = 71 letter = 75 letter = 78 letter = 65 letter = 66 letter = 70 letter = 76 letter = 73 letter = 78 letter = 83 letter = 65 letter = 66 letter = 72 letter = 67 letter = 65 letter = 66 letter = 72 letter = 85 letter = 77 letter = 78 letter = 65 letter = 70 letter = 74 letter = 79 letter = 81 letter = 82 letter = 65 letter = 68 letter = 67 letter = 66 letter = 82 letter = 69 letter = 86 letter = 65 letter = 66 letter = 72 letter = 85 letter = 75 letter = 81 letter = 65 letter = 66 letter = 71 letter = 75 letter = 72 letter = 86 letter = 69 letter = 77 letter = 78 letter = 79 letter = 80 letter = 82 letter = 90 letter = 65 letter = 66 letter = 79 letter = 68 letter = 90 letter = 65 letter = 66 letter = 71 letter = 75 letter = 72 letter = 86 letter = 69 letter = 77 letter = 78 letter = 79 letter = 84 letter = 65 letter = 66 letter = 71 letter = 75 letter = 72 letter = 67 letter = 65 letter = 66 letter = 70 letter = 67 letter = 68 letter = 80 letter = 71 letter = 69 letter = 72 letter = 74 letter = 75 letter = 65 letter = 66 letter = 70 letter = 71 letter = 74 letter = 78 letter = 88 letter = 65 letter = 66 letter = 70 letter = 67 letter = 68 letter = 80 letter = 77 letter = 69 letter = 72 letter = 81 letter = 65 letter = 66 letter = 70 letter = 67 letter = 69 letter = 77 letter = 79 letter = 65 letter = 66 letter = 79 letter = 74 letter = 65 letter = 66 letter = 71 letter = 82 letter = 65 letter = 66 letter = 70 letter = 67 letter = 68 letter = 88 letter = 65 letter = 66 letter = 71 letter = 65 letter = 66 letter = 70 letter = 88 letter = 67 letter = 68 letter = 82 letter = 90 letter = 65 letter = 66 letter = 70 letter = 67 letter = 68 letter = 80 letter = 81 letter = 76 letter = 65 letter = 66 letter = 70 letter = 67 letter = 68 letter = 75 letter = 77 letter = 82 letter = 65 letter = 70 letter = 74 letter = 79 letter = 81 letter = 65 letter = 66 letter = 70 letter = 67 letter = 68 letter = 80 letter = 77 letter = 71 letter = 74 letter = 65 letter = 66 letter = 70 letter = 67 letter = 68 letter = 80 letter = 77 letter = 88 letter = 69 letter = 72 letter = 65 letter = 66 letter = 70 letter = 67 letter = 68 letter = 69 letter = 81 letter = 65 letter = 66 letter = 71 letter = 75 letter = 72 letter = 86 letter = 69 letter = 83 letter = 65 letter = 66 letter = 70 letter = 67 letter = 68 letter = 80 letter = 71 letter = 69 letter = 72 letter = 85 letter = 65 letter = 69 letter = 66 letter = 72 letter = 68 letter = 70 letter = 77 letter = 71 letter = 74 letter = 82 letter = 65 letter = 66 letter = 72 letter = 85 letter = 75 letter = 80 letter = 86 letter = 78 letter = 65 letter = 68 letter = 67 letter = 71 letter = 65 letter = 66 letter = 71 letter = 75 letter = 81 letter = 88 letter = 65 letter = 66 letter = 70 letter = 76 letter = 72 letter = 65 letter = 68 letter = 67 letter = 66 letter = 82 letter = 69 letter = 75 letter = 79 letter = 65 letter = 66 letter = 70 letter = 67 letter = 68 letter = 69 letter = 73 letter = 65 letter = 66 letter = 72 letter = 85 letter = 75 letter = 80 letter = 86 letter = 68 letter = 82 letter = 87 letter = 65 letter = 66 letter = 70 letter = 67 letter = 68 letter = 69 letter = 73 letter = 74 letter = 78 letter = 79 letter = 65 letter = 66 letter = 70 letter = 67 letter = 69 letter = 76 letter = 80 letter = 65 letter = 66 letter = 79 letter = 68 letter = 69 letter = 72 letter = 65 letter = 66 letter = 70 letter = 76 letter = 73 letter = 90 letter = 65 letter = 66 letter = 70 letter = 67 letter = 68 letter = 75 letter = 77 letter = 82 letter = 84 letter = 65 letter = 66 letter = 69 letter = 78 letter = 65 letter = 66 letter = 72 letter = 85 letter = 77 letter = 65 letter = 66 letter = 72 letter = 85 letter = 75 letter = 80 letter = 76 letter = 65 letter = 66 letter = 70 letter = 67 letter = 68 letter = 80 letter = 81 letter = 73 letter = 65 letter = 66 letter = 72 letter = 85 letter = 75 letter = 80 letter = 67 letter = 65 letter = 68 letter = 72 letter = 73 letter = 75 letter = 65 letter = 66 letter = 70 letter = 67 letter = 74 letter = 78 letter = 65 letter = 66 letter = 70 letter = 68 letter = 71 letter = 72 letter = 76 letter = 65 letter = 69 letter = 66 letter = 72 letter = 68 letter = 70 letter = 77 letter = 87 letter = 65 letter = 66 letter = 70 letter = 88 letter = 67 letter = 68 letter = 79 letter = 65 letter = 69 letter = 66 letter = 72 letter = 65 letter = 66 letter = 70 letter = 67 letter = 68 letter = 80 letter = 77 letter = 75 letter = 79 letter = 73 letter = 74 letter = 65 letter = 69 letter = 76 letter = 77 letter = 79 letter = 65 letter = 66 letter = 70 letter = 88 letter = 67 letter = 74 letter = 65 letter = 66 letter = 72 letter = 67 letter = 89 letter = 65 letter = 66 letter = 70 letter = 68 letter = 71 letter = 72 letter = 73 letter = 65 letter = 68 letter = 67 letter = 66 letter = 70 letter = 72 letter = 83 letter = 87 letter = 65 letter = 66 letter = 70 letter = 67 letter = 68 letter = 80 letter = 71 letter = 69 letter = 84 letter = 65 letter = 66 letter = 71 letter = 69 letter = 65 letter = 66 letter = 71 letter = 75 letter = 81 letter = 65 letter = 66 letter = 70 letter = 67 letter = 68 letter = 80 letter = 77 letter = 75 letter = 79 letter = 69 letter = 83 letter = 78 letter = 81 letter = 65 letter = 70 letter = 74 letter = 79 letter = 65 letter = 66 letter = 70 letter = 67 letter = 69 letter = 76 letter = 71 letter = 65 letter = 66 letter = 70 letter = 67 letter = 68 letter = 80 letter = 81 letter = 65 letter = 66 letter = 70 letter = 67 letter = 68 letter = 80 letter = 77 letter = 75 letter = 79 letter = 71 letter = 72 letter = 65 letter = 66 letter = 69 letter = 78 letter = 81 letter = 65 letter = 66 letter = 70 letter = 67 letter = 68 letter = 80 letter = 71 letter = 75 letter = 65 letter = 66 letter = 70 letter = 76 letter = 65 letter = 66 letter = 70 letter = 67 letter = 68 letter = 80 letter = 77 letter = 88 letter = 69 letter = 65 letter = 66 letter = 70 letter = 67 letter = 68 letter = 75 letter = 69 letter = 84 letter = 65 letter = 68 letter = 67 letter = 66 letter = 70 letter = 72 letter = 65 letter = 66 letter = 71 letter = 75 letter = 73 letter = 65 letter = 66 letter = 72 letter = 85 letter = 75 letter = 74 letter = 65 letter = 66 letter = 70 letter = 67 letter = 68 letter = 80 letter = 77 letter = 75 letter = 79 letter = 69 letter = 83 letter = 87 letter = 71 letter = 72 letter = 86 letter = 65 letter = 66 letter = 70 letter = 76 letter = 71 letter = 74 letter = 65 letter = 66 letter = 70 letter = 67 letter = 68 letter = 80 letter = 77 letter = 75 letter = 79 letter = 69 letter = 83 letter = 73 letter = 89 letter = 65 letter = 68 letter = 72 letter = 73 letter = 65 letter = 66 letter = 70 letter = 67 letter = 89 letter = 79 letter = 65 letter = 68 letter = 67 letter = 65 letter = 66 letter = 70 letter = 71 letter = 72 letter = 65 letter = 66 letter = 71 letter = 75 letter = 72 letter = 86 letter = 69 letter = 77 letter = 78 letter = 79 letter = 80 letter = 85 letter = 65 letter = 70 letter = 74 letter = 65 letter = 66 letter = 71 letter = 69 letter = 76 letter = 65 letter = 66 letter = 70 letter = 67 letter = 77 letter = 65 letter = 69...
3   Fail