Cody

Problem 42716. Number of occurrences of letter in a text

Solution 1973543

Submitted on 13 Oct 2019
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   Fail
input_text = 'bla, BLA, bla'; occurrence_correct = [3 3 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; assert(isequal(letters_occurrence(input_text),occurrence_correct))

Brace indexing is not supported for variables of this type. Error in letters_occurrence (line 2) input_text=[input_text{:}] Error in Test1 (line 3) assert(isequal(letters_occurrence(input_text),occurrence_correct))

2   Pass
input_text = {'King Richard: A horse, a horse! My kingdom for a horse!'}; occurrence_correct = [4 0 1 2 3 1 2 4 3 0 2 0 2 2 5 0 0 6 3 0 0 0 0 0 1 0]; assert(isequal(letters_occurrence(input_text),occurrence_correct))

input_text = 'King Richard: A horse, a horse! My kingdom for a horse!' input_text = Columns 1 through 30 107 105 110 103 32 114 105 99 104 97 114 100 58 32 97 32 104 111 114 115 101 44 32 97 32 104 111 114 115 101 Columns 31 through 55 33 32 109 121 32 107 105 110 103 100 111 109 32 102 111 114 32 97 32 104 111 114 115 101 33 occurrence = 4 k = 2 occurrence = 4 0 k = 3 occurrence = 4 0 1 k = 4 occurrence = 4 0 1 2 k = 5 occurrence = 4 0 1 2 3 k = 6 occurrence = 4 0 1 2 3 1 k = 7 occurrence = 4 0 1 2 3 1 2 k = 8 occurrence = 4 0 1 2 3 1 2 4 k = 9 occurrence = 4 0 1 2 3 1 2 4 3 k = 10 occurrence = 4 0 1 2 3 1 2 4 3 0 k = 11 occurrence = 4 0 1 2 3 1 2 4 3 0 2 k = 12 occurrence = 4 0 1 2 3 1 2 4 3 0 2 0 k = 13 occurrence = 4 0 1 2 3 1 2 4 3 0 2 0 2 k = 14 occurrence = 4 0 1 2 3 1 2 4 3 0 2 0 2 2 k = 15 occurrence = 4 0 1 2 3 1 2 4 3 0 2 0 2 2 5 k = 16 occurrence = 4 0 1 2 3 1 2 4 3 0 2 0 2 2 5 0 k = 17 occurrence = 4 0 1 2 3 1 2 4 3 0 2 0 2 2 5 0 0 k = 18 occurrence = 4 0 1 2 3 1 2 4 3 0 2 0 2 2 5 0 0 6 k = 19 occurrence = 4 0 1 2 3 1 2 4 3 0 2 0 2 2 5 0 0 6 3 k = 20 occurrence = 4 0 1 2 3 1 2 4 3 0 2 0 2 2 5 0 0 6 3 0 k = 21 occurrence = 4 0 1 2 3 1 2 4 3 0 2 0 2 2 5 0 0 6 3 0 0 k = 22 occurrence = 4 0 1 2 3 1 2 4 3 0 2 0 2 2 5 0 0 6 3 0 0 0 k = 23 occurrence = 4 0 1 2 3 1 2 4 3 0 2 0 2 2 5 0 0 6 3 0 0 0 0 k = 24 occurrence = 4 0 1 2 3 1 2 4 3 0 2 0 2 2 5 0 0 6 3 0 0 0 0 0 k = 25 occurrence = 4 0 1 2 3 1 2 4 3 0 2 0 2 2 5 0 0 6 3 0 0 0 0 0 1 k = 26 occurrence = 4 0 1 2 3 1 2 4 3 0 2 0 2 2 5 0 0 6 3 0 0 0 0 0 1 0 k = 27

3   Pass
input_text = {'Thus much let me avow--'; 'You are not wrong, who deem'; 'That my days have been a dream;'}; occurrence_correct = [7 1 1 3 9 0 1 5 0 0 0 1 5 3 5 0 0 3 2 5 3 2 3 0 3 0]; assert(isequal(letters_occurrence(input_text),occurrence_correct))

input_text = 'Thus much let me avow--You are not wrong, who deemThat my days have been a dream;' input_text = Columns 1 through 30 116 104 117 115 32 109 117 99 104 32 108 101 116 32 109 101 32 97 118 111 119 45 45 121 111 117 32 97 114 101 Columns 31 through 60 32 110 111 116 32 119 114 111 110 103 44 32 119 104 111 32 100 101 101 109 116 104 97 116 32 109 121 32 100 97 Columns 61 through 81 121 115 32 104 97 118 101 32 98 101 101 110 32 97 32 100 114 101 97 109 59 occurrence = 7 k = 2 occurrence = 7 1 k = 3 occurrence = 7 1 1 k = 4 occurrence = 7 1 1 3 k = 5 occurrence = 7 1 1 3 9 k = 6 occurrence = 7 1 1 3 9 0 k = 7 occurrence = 7 1 1 3 9 0 1 k = 8 occurrence = 7 1 1 3 9 0 1 5 k = 9 occurrence = 7 1 1 3 9 0 1 5 0 k = 10 occurrence = 7 1 1 3 9 0 1 5 0 0 k = 11 occurrence = 7 1 1 3 9 0 1 5 0 0 0 k = 12 occurrence = 7 1 1 3 9 0 1 5 0 0 0 1 k = 13 occurrence = 7 1 1 3 9 0 1 5 0 0 0 1 5 k = 14 occurrence = 7 1 1 3 9 0 1 5 0 0 0 1 5 3 k = 15 occurrence = 7 1 1 3 9 0 1 5 0 0 0 1 5 3 5 k = 16 occurrence = 7 1 1 3 9 0 1 5 0 0 0 1 5 3 5 0 k = 17 occurrence = 7 1 1 3 9 0 1 5 0 0 0 1 5 3 5 0 0 k = 18 occurrence = 7 1 1 3 9 0 1 5 0 0 0 1 5 3 5 0 0 3 k = 19 occurrence = 7 1 1 3 9 0 1 5 0 0 0 1 5 3 5 0 0 3 2 k = 20 occurrence = 7 1 1 3 9 0 1 5 0 0 0 1 5 3 5 0 0 3 2 5 k = 21 occurrence = 7 1 1 3 9 0 1 5 0 0 0 1 5 3 5 0 0 3 2 5 3 k = 22 occurrence = 7 1 1 3 9 0 1 5 0 0 0 1 5 3 5 0 0 3 2 5 3 2 k = 23 occurrence = 7 1 1 3 9 0 1 5 0 0 0 1 5 3 5 0 0 3 2 5 3 2 3 k = 24 occurrence = 7 1 1 3 9 0 1 5 0 0 0 1 5 3 5 0 0 3 2 5 3 2 3 0 k = 25 occurrence = 7 1 1 3 9 0 1 5 0 0 0 1 5 3 5 0 0 3 2 5 3 2 3 0 3 k = 26 occurrence = 7 1 1 3 9 0 1 5 0 0 0 1 5 3 5 0 0 3 2 5 3 2 3 0 3 0 k = 27

Suggested Problems

More from this Author2

Community Treasure Hunt

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

Start Hunting!