solved prob 3 in ruby