Problem 34 in Ruby.