A Scrambled Words Variant

October 11, 2019

In the previous exercise, we wrote a program to scramble the letters in each word of a string, retaining capitalization and punctuation: “Programming Praxis is fun!” became something like “Grprnimaogm Srxpia is unf!” Today’s exercise is the same, but with a simple variation: the first and last letters of each word must remain unchanged, so we might see something like “Prgrnimaomg Prxias is fun!”

Your task is to modify your previous program in the minimal possible way into a program that scrambles the letters in the interior of the words in a string, retaining capitalization and punctuation. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

Advertisement

Pages: 1 2