Solved problem 15 in ruby