From: James Edward Gray II Date: 2005-11-03T22:41:41+09:00 Subject: Fwd: Please Forward: Ruby Quiz Submission --Apple-Mail-3-246755678 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Begin forwarded message: > From: Scott Bauer > Date: November 2, 2005 11:57:29 PM CST > To: submission@rubyquiz.com > Subject: Please Forward: Ruby Quiz Submission > > > Use ruby dryer.rb file_to_dry.txt to generate Ruby code to re- > create the input file. 'Tis quite funky and doesn't meet the > readability guideline, but it works for the example given. > > Thanks, > Scott Bauer --Apple-Mail-3-246755678 Content-Transfer-Encoding: 7bit Content-Type: application/octet-stream; x-unix-mode=0666; name="dryer.rb" Content-Disposition: attachment; filename=dryer.rb original = ARGF.read tokens = original.scan(/.{5,}?\b/).uniq.sort_by { |t| t.size }.reverse tokens.size.times do |index| original.gsub!(Regexp.new(Regexp.escape(tokens[index])), ":#{index}-") end $stdout << <<"RONCO_REHYDRATOR" original = <<"DRIED_THINGS" #{original} DRIED_THINGS index = -1 Marshal.load( <<"YUMMY_SERIAL" #{Marshal.dump(tokens)} YUMMY_SERIAL ).each do |token| original.gsub!(Regexp.new(":\#\{index += 1\}-"), token) end $stdout << original RONCO_REHYDRATOR --Apple-Mail-3-246755678 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed --Apple-Mail-3-246755678--