Problem 44853. Mean number of letters per word (Hard)
The previous problem in this series is 44852.
Given a character array, s, representing a sentence, return a and g, the arithmetic and geometric means, respectively, of the number of letters per word in the given sentence. Round your answer to three decimal digits.
You may make the following assumptions:
1. Not all characters in the array are either letters or spaces. There may also be numeric characters, as well as punctuation.
2. There may be redundant spaces in the sentence.
3. Punctuation does not count as a letter and cannot constitute a word in itself. Numbers also do not count as letters, but can constitute a word.
4. There can be any number of characters and/or words in the sentence, including zero. When there are zero words in the sentence, return empty matrices for a and g.
Example:
c = 'The quick brown fox jumps over the lazy dog';
a = 3.889; g = 3.792
Example:
c = 'Another one bites the dust';
a = 4.400; g = 4.169
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers13
Suggested Problems
-
Project Euler: Problem 8, Find largest product in a large string of numbers
1100 Solvers
-
463 Solvers
-
1091 Solvers
-
Generate N equally spaced intervals between -L and L
868 Solvers
-
Find and replaces spaces from a input string with *
162 Solvers
More from this Author45
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!