finished problem 16 in ruby