From: Barry Dmytro Date: 2006-04-24T06:47:36+09:00 Subject: [QUIZ][SOLUTION] Text Munger --XsQoSWH+UP9D9v3l Content-Type: text/plain; charset=us-ascii Content-Disposition: inline It expects stuff to be piped to it. ~> cat file.txt | ./76.rb Took all of 10 minutes to write... First version was 5 lines, but expanded it to 15 to add some handling of different situations. Kind Regards, -------------------------------------------------------------------- Barry Dmytro badcherry@mailc.net http://badcherry.org/ -------------------------------------------------------------------- --XsQoSWH+UP9D9v3l Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="76.rb" #!/usr/bin/env ruby # cat file.txt | ./76.rb while true s = gets;n = "" exit if s.nil?;s = s.gsub(/\n/," ") exit if s.gsub(/ /,"").empty? s.split.each do |w| x = w.split "" f = x.shift;l = x.pop f << x.shift if f == "\"" l = x.pop + l if l == "." or l == "!" or l == "?" or l == "," l = x.pop + l if l == "\"" x = f + (x.sort_by {rand}).to_s + l n << x << " " end puts n end --XsQoSWH+UP9D9v3l Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="txt.txt" It is very easy to learn how to speak and write correctly, as for all purposes of ordinary conversation and communication, only about 2,000 different words are required. The mastery of just twenty hundred words, the knowing where to place them, will make us not masters of the English language, but masters of correct speaking and writing. Small number, you will say, compared with what is in the dictionary! But nobody ever uses all the words in the dictionary or could use them did he live to be the age of Methuselah, and there is no necessity for using them. --XsQoSWH+UP9D9v3l--