Problem 31 in Ruby complete