solved problem 15 in ruby