From: James Edward Gray II Date: 2007-09-13T03:07:06+09:00 Subject: Re: Ruby Quiz Submission [resent in plain text] On Sep 8, 2007, at 1:59 PM, James Edward Gray II wrote: > Begin forwarded message: > >> # I would appreciate any >> # comments improving my idiomatic ruby. Some thoughts� >> letters = {} >> letters.default = 0 That could be: letters = Hash.new(0) >> #put letters in a hash >> s = sentence.gsub(/[^A-Z]/,'') >> s.split('').each do |letter| >> letters[letter] = letters[letter] + 1 >> end Instead of gsub() and split(), you could use scan(). You can take another shortcut here with +=: sentence.scan(/[A-Z]/) { |l| letters[l] += 1 } >> print i.to_s + "." We generally favor interpolation in Ruby so we can avoid these casting calls: print "#{i}." Great solution though. Thanks for sending it in. James Edward Gray II