resolved problem 13 in Ruby