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
6 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers2080
Suggested Problems
-
Find all elements less than 0 or greater than 10 and replace them with NaN
15779 Solvers
-
middleAsColumn: Return all but first and last element as a column vector
646 Solvers
-
Implement simple rotation cypher
1095 Solvers
-
Number of Even Elements in Fibonacci Sequence
1633 Solvers
-
1771 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!
Put more test cases in. Makes cheating too tempting.
the regexp solution is great
Adding a test case containing words with hyphens like 'hard-working' will make this problem more challenging.
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.
interesting question
I thought the empty set test was uncalled for. Might as well add in numeric arguments if you're wanting to make a case for checking if your inputs are valid.