Problem 32 in Ruby.