Problem 38 in Ruby.