Cody

# Problem 1184. Hangman (strategy)

Solution 292312

Submitted on 30 Jul 2013 by Jean-Marie Sainthillier
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));

ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word ZONE; Step 1; Word list BUZZ COZY DOZE FUZZ GAZE HAZE JAZZ LAZY SIZE ZERO ZONE ; Guess Z ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word ONE; Step 2; Word list ERO ONE ; Guess E ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word ON; Step 3; Word list ON ; Guess O ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word N; Step 4; Word list N ; Guess N ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word GAZE; Step 1; Word list BUZZ COZY DOZE FUZZ GAZE HAZE JAZZ LAZY SIZE ZERO ZONE ; Guess Z ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word GAE; Step 2; Word list COY DOE GAE HAE LAY SIE ; Guess E ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word GA; Step 3; Word list DO GA HA SI ; Guess A ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word G; Step 4; Word list G H ; Guess H ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word G; Step 5; Word list G ; Guess G ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word HAZE; Step 1; Word list BUZZ COZY DOZE FUZZ GAZE HAZE JAZZ LAZY SIZE ZERO ZONE ; Guess Z ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word HAE; Step 2; Word list COY DOE GAE HAE LAY SIE ; Guess E ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word HA; Step 3; Word list DO GA HA SI ; Guess A ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word H; Step 4; Word list G H ; Guess H ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word DOZE; Step 1; Word list BUZZ COZY DOZE FUZZ GAZE HAZE JAZZ LAZY SIZE ZERO ZONE ; Guess Z ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word DOE; Step 2; Word list COY DOE GAE HAE LAY SIE ; Guess E ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word DO; Step 3; Word list DO GA HA SI ; Guess A ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word DO; Step 4; Word list DO SI ; Guess O ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word D; Step 5; Word list D ; Guess D ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word ZERO; Step 1; Word list BUZZ COZY DOZE FUZZ GAZE HAZE JAZZ LAZY SIZE ZERO ZONE ; Guess Z ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word ERO; Step 2; Word list ERO ONE ; Guess E ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word RO; Step 3; Word list RO ; Guess O ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word R; Step 4; Word list R ; Guess R ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word LAZY; Step 1; Word list BUZZ COZY DOZE FUZZ GAZE HAZE JAZZ LAZY SIZE ZERO ZONE ; Guess Z ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word LAY; Step 2; Word list COY DOE GAE HAE LAY SIE ; Guess E ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word LAY; Step 3; Word list COY LAY ; Guess Y ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word LA; Step 4; Word list CO LA ; Guess A ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word L; Step 5; Word list L ; Guess L ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word FUZZ; Step 1; Word list BUZZ COZY DOZE FUZZ GAZE HAZE JAZZ LAZY SIZE ZERO ZONE ; Guess Z ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word FU; Step 2; Word list BU FU JA ; Guess U ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word F; Step 3; Word list B F ; Guess F ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word JAZZ; Step 1; Word list BUZZ COZY DOZE FUZZ GAZE HAZE JAZZ LAZY SIZE ZERO ZONE ; Guess Z ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word JA; Step 2; Word list BU FU JA ; Guess U ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word JA; Step 3; Word list JA ; Guess A ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word J; Step 4; Word list J ; Guess J ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word COZY; Step 1; Word list BUZZ COZY DOZE FUZZ GAZE HAZE JAZZ LAZY SIZE ZERO ZONE ; Guess Z ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word COY; Step 2; Word list COY DOE GAE HAE LAY SIE ; Guess E ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word COY; Step 3; Word list COY LAY ; Guess Y ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word CO; Step 4; Word list CO LA ; Guess A ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word CO; Step 5; Word list CO ; Guess O ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word C; Step 6; Word list C ; Guess C ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word SIZE; Step 1; Word list BUZZ COZY DOZE FUZZ GAZE HAZE JAZZ LAZY SIZE ZERO ZONE ; Guess Z ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word SIE; Step 2; Word list COY DOE GAE HAE LAY SIE ; Guess E ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word SI; Step 3; Word list DO GA HA SI ; Guess A ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word SI; Step 4; Word list DO SI ; Guess O ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word SI; Step 5; Word list SI ; Guess I ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word S; Step 6; Word list S ; Guess S ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word BUZZ; Step 1; Word list BUZZ COZY DOZE FUZZ GAZE HAZE JAZZ LAZY SIZE ZERO ZONE ; Guess Z ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word BU; Step 2; Word list BU FU JA ; Guess U ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word B; Step 3; Word list B F ; Guess F ans = ETAOINSHRDLCUMWFGYPBVKJXQZ Target word B; Step 4; Word list B ; Guess B 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));

ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ...

3   Fail
%% rng default; a.words0=cellstr(unique(char('A'+ceil(26*rand([200,4]).^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));

ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSHRDLCUMWFGYPBVKJXQZ ans = ETAOINSH