Cody

# Problem 1182. Hangman (easy)

Solution 3015745

Submitted on 1 Oct 2020 by Simone Corti
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

letter = 1×26 cell array Columns 1 through 19 {'A'} {'B'} {'C'} {'D'} {'E'} {'F'} {'G'} {'H'} {'I'} {'J'} {'K'} {'L'} {'M'} {'N'} {'O'} {'P'} {'Q'} {'R'} {'S'} Columns 20 through 26 {'T'} {'U'} {'V'} {'W'} {'X'} {'Y'} {'Z'} s = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 s = 2 3 0 2 2 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 letter = 'B' letter = 'B'

2   Pass
words={'BUZZ','COZY','DOZE','FUZZ','GAZE','HAZE','JAZZ','LAZY','SIZE','ZERO','ZONE'}; assert(isequal(hangman(words),'Z'));

letter = 1×26 cell array Columns 1 through 19 {'A'} {'B'} {'C'} {'D'} {'E'} {'F'} {'G'} {'H'} {'I'} {'J'} {'K'} {'L'} {'M'} {'N'} {'O'} {'P'} {'Q'} {'R'} {'S'} Columns 20 through 26 {'T'} {'U'} {'V'} {'W'} {'X'} {'Y'} {'Z'} s = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 s = 4 1 1 1 6 1 1 1 1 1 0 1 0 1 4 0 0 1 1 0 2 0 0 0 2 11 letter = 'Z' letter = 'Z'

3   Pass
rng default; words=unique(char('A'+randi(26,[100,3])-1),'rows'); assert(isequal(sum(any(words==hangman(cellstr(words)'),2)),max(arrayfun(@(x)sum(any(words==x,2)),'A':'Z'))));

letter = 1×26 cell array Columns 1 through 19 {'A'} {'B'} {'C'} {'D'} {'E'} {'F'} {'G'} {'H'} {'I'} {'J'} {'K'} {'L'} {'M'} {'N'} {'O'} {'P'} {'Q'} {'R'} {'S'} Columns 20 through 26 {'T'} {'U'} {'V'} {'W'} {'X'} {'Y'} {'Z'} s = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 s = 10 7 12 12 14 10 18 7 8 10 8 12 13 11 9 8 11 10 10 11 14 10 6 15 16 8 letter = 'G' letter = 'G'

4   Pass
rng default; words=unique(char('A'+randi(26,[200,4])-1),'rows'); assert(isequal(sum(any(words==hangman(cellstr(words)'),2)),max(arrayfun(@(x)sum(any(words==x,2)),'A':'Z'))));

letter = 1×26 cell array Columns 1 through 19 {'A'} {'B'} {'C'} {'D'} {'E'} {'F'} {'G'} {'H'} {'I'} {'J'} {'K'} {'L'} {'M'} {'N'} {'O'} {'P'} {'Q'} {'R'} {'S'} Columns 20 through 26 {'T'} {'U'} {'V'} {'W'} {'X'} {'Y'} {'Z'} s = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 s = 24 31 34 32 36 26 34 24 25 21 27 36 33 32 27 31 32 32 31 32 29 31 22 28 30 24 letter = 2×1 char array 'E' 'L' letter = 'E'

5   Pass
rng default; words=unique(char('A'+randi(26,[500,5])-1),'rows'); assert(isequal(sum(any(words==hangman(cellstr(words)'),2)),max(arrayfun(@(x)sum(any(words==x,2)),'A':'Z'))));

letter = 1×26 cell array Columns 1 through 19 {'A'} {'B'} {'C'} {'D'} {'E'} {'F'} {'G'} {'H'} {'I'} {'J'} {'K'} {'L'} {'M'} {'N'} {'O'} {'P'} {'Q'} {'R'} {'S'} Columns 20 through 26 {'T'} {'U'} {'V'} {'W'} {'X'} {'Y'} {'Z'} s = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 s = 75 89 97 94 93 84 92 74 85 80 103 104 66 95 97 97 85 87 99 97 86 93 75 89 85 87 letter = 'L' letter = 'L'

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!