Problem 46 in Ruby.