Problem 44853. Mean number of letters per word (Hard)

  • Created by HH

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

35.38% Correct | 64.62% Incorrect
Last Solution submitted on Jun 09, 2024

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers13

Suggested Problems

More from this Author45

Community Treasure Hunt

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

Start Hunting!