Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Problem 831. Find mistyped words in text (mixed-up letters)

Created by Matt Eicholtz

Mistyped words are a regular occurrence in emails, texts, status updates, and the like. Many times, people send or post a second text with the correct word, usually preceded by an asterisk. In perhaps the most common case, the mistyped word contains all of the correct letters, but in the wrong order (e.g. 'I loev MATLAB').

In this problem, you are given two strings: (1) the original text and (2) the correct word(s), each preceded by an asterisk. Your function should output a cell array of the mistyped words that are being corrected.

Notes

  • Assume each mistyped word has all the correct letters, but in the wrong order
  • Assume there is only one possible option for each correct word in the second input string
  • The original text may contain punctuation, but do not include punctuation in the output
  • Corrections are case-insensitive, but the output should contain the mistyped words as written in the original text.
  • There may be more than one mistyped word; if so, the correct words are presented in order (i.e. the N-th word in the second input string corresponds to the N-th mistyped word in the original text)
  • If the second input string is empty, return an empty cell array

Example

If

 str = 'Which sword are mistyped in this srting?';
 correct_words = '*words *string';

then

 mistyped_words = {'sword','srting'};

Tags

Problem Group

Solution Statistics

11 correct solutions 17 incorrect solutions
Last solution submitted on Nov 10, 2014