Cody

# Problem 1182. Hangman (easy)

Solution 3015595

Submitted on 1 Oct 2020
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'} 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'} letter = "Z"

3   Fail
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'} letter = "G"

Error using == Comparison between char and string requires the char input to be a row vector. Error in Test3 (line 3) assert(isequal(sum(any(words==hangman(cellstr(words)'),2)),max(arrayfun(@(x)sum(any(words==x,2)),'A':'Z'))));

4   Fail
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'} letter = 1×2 string array "E" "L"

Error using == Comparison between char and string requires the char input to be a row vector. Error in Test4 (line 3) assert(isequal(sum(any(words==hangman(cellstr(words)'),2)),max(arrayfun(@(x)sum(any(words==x,2)),'A':'Z'))));

5   Fail
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'} letter = "L"

Error using == Comparison between char and string requires the char input to be a row vector. Error in Test5 (line 3) assert(isequal(sum(any(words==hangman(cellstr(words)'),2)),max(arrayfun(@(x)sum(any(words==x,2)),'A':'Z'))));

### Community Treasure Hunt

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

Start Hunting!