Problem 11 in Ruby