Ruby Quiz wrote: > Your task for this quiz, then, is to take a text as input and output the text in > this fashion. Scramble each word's center (leaving the first and last letters of > each word intact). Whitespace, punctuation, numbers -- anything that isn't a > word -- should also remain unchanged. My solution: === snip === # Ruby Quiz 76 # http://www.rubyquiz.com/quiz76.html # # Solution of Tom Moertel # http://blog.moertel.com/ # 2006-04-21 # # Usage: munge.rb [inputs...] class String def munge! (length - 2).downto(2) do |i| j = rand(i) + 1 self[i], self[j] = self[j], self[i] end self end end while line = gets puts line.gsub(/\w+/) { |s| s.munge! } end === end === A few notes: I took the term "scramble" in the task definition to mean randomly permute because some occurrences of words in the example text were apparently unchanged by the scrambling transformation (e.g., "keep" and "being" in the tenth line) and some words that had multiple occurrences were scrambled differently for each occurrence (e.g., "remvpidtee" in the second line vs. "retpmevide" in the fourth from the last line). str.munge! (fairly) permutes the inner characters of +str+ and has no effect on strings of three or fewer characters. I used +gets+ in the main I/O loop in order to get sensible command-line input handling for free. Cheers, Tom