Cody

Problem 42716. Number of occurrences of letter in a text

Solution 1973542

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   Pass
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))

input_text = 98 108 97 44 32 98 108 97 44 32 98 108 97 m = 'abcdefghijklmnopqrstuvwxyz' occurrence = 3 k = 2 occurrence = 3 3 k = 3 occurrence = 3 3 0 k = 4 occurrence = 3 3 0 0 k = 5 occurrence = 3 3 0 0 0 k = 6 occurrence = 3 3 0 0 0 0 k = 7 occurrence = 3 3 0 0 0 0 0 k = 8 occurrence = 3 3 0 0 0 0 0 0 k = 9 occurrence = 3 3 0 0 0 0 0 0 0 k = 10 occurrence = 3 3 0 0 0 0 0 0 0 0 k = 11 occurrence = 3 3 0 0 0 0 0 0 0 0 0 k = 12 occurrence = 3 3 0 0 0 0 0 0 0 0 0 3 k = 13 occurrence = 3 3 0 0 0 0 0 0 0 0 0 3 0 k = 14 occurrence = 3 3 0 0 0 0 0 0 0 0 0 3 0 0 k = 15 occurrence = 3 3 0 0 0 0 0 0 0 0 0 3 0 0 0 k = 16 occurrence = 3 3 0 0 0 0 0 0 0 0 0 3 0 0 0 0 k = 17 occurrence = 3 3 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 k = 18 occurrence = 3 3 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 k = 19 occurrence = 3 3 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 k = 20 occurrence = 3 3 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 k = 21 occurrence = 3 3 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 k = 22 occurrence = 3 3 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 k = 23 occurrence = 3 3 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 k = 24 occurrence = 3 3 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 0 k = 25 occurrence = 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 k = 26 occurrence = 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 k = 27

2   Fail
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))

Error using double Conversion to double from cell is not possible. Error in letters_occurrence (line 2) input_text=double(lower(input_text)) Error in Test2 (line 3) assert(isequal(letters_occurrence(input_text),occurrence_correct))

3   Fail
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))

Error using double Conversion to double from cell is not possible. Error in letters_occurrence (line 2) input_text=double(lower(input_text)) Error in Test3 (line 3) assert(isequal(letters_occurrence(input_text),occurrence_correct))

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!