Solved probelm 14 in ruby