Problem 88. It dseon't mettar waht oedrr the lrettes in a wrod are.
An internet meme from 2003 (read more here) asserted that readers are relatively insensitive to letter order in words, so long as the first and last letters are unchanged.
Given a string of words s, take each word in turn and reverse the order of letters 2 through n-1, where n is the length of the words. Non-alphabetic characters should remain in place.
So if
sIn = 'hello'
then
sOut = 'hlleo'
And if
sIn = 'This is the first time I have used MATLAB.'
then
sOut = 'Tihs is the fsrit tmie I hvae uesd MALTAB.'
Solution Stats
Problem Comments
-
5 Comments
Show
2 older comments
Hans Kramer
on 25 Oct 2018
Put more test cases in. Makes cheating too tempting.
danteliujie
on 18 Mar 2019
the regexp solution is great
jo gayong
on 10 Jul 2019
Adding a test case containing words with hyphens like 'hard-working' will make this problem more challenging.
Aaron Greisen
on 2 Oct 2022
Needs more test cases. Some would fail with input sIn = 'what is a chain' because of the 'ha' occurring in the middle of both in 'what' and 'chain'. Also needs test cases with hyphened words.
Akash
on 4 Mar 2024
interesting question
Solution Comments
Show commentsProblem Recent Solvers1779
Suggested Problems
-
4233 Solvers
-
Create a cell array out of a struct
1777 Solvers
-
Project Euler: Problem 7, Nth prime
1412 Solvers
-
419 Solvers
-
Back to basics 13 - Input variables
266 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!