From: James Edward Gray II Date: 2006-04-24T04:49:16+09:00 Subject: Fwd: Please Forward: Ruby Quiz Submission --Apple-Mail-2-10824128 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Begin forwarded message: > From: Jeroen Heijmans > Date: April 23, 2006 5:09:35 AM CDT > To: submission@rubyquiz.com > Subject: Please Forward: Ruby Quiz Submission > > Last week, I was trying to find some small Ruby problems to learn > using Ruby, and Ruby Quiz is a great way to do that - thanks! > Attached is my shot at #76, which was relatively easy compared to > some of the older ones I tried. I have the feeling the code could > be more compact than what I have, but I'll see that when other > solutions are posted. > > Jeroen Heijmans > --Apple-Mail-2-10824128 Content-Transfer-Encoding: 7bit Content-Type: text/x-ruby-script; x-mac-type=54455854; x-unix-mode=0644; name="munger.rb" Content-Disposition: attachment; filename=munger.rb class String MANGLABLE_WORD = /^[[:alpha:]]{4,}$/ def to_mangled_s split(/\b/).map {|w| w.mangled_word }.join end def mangled_word if match(MANGLABLE_WORD) self[0,1] + self[1...-1].scramble! + self[-1, 1] else self end end def scramble! scrambled = "" scrambled << slice!(rand(length), 1) until (length == 0) replace(scrambled) end end puts ARGF.read.to_mangled_s --Apple-Mail-2-10824128 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed --Apple-Mail-2-10824128--