solved problem 21 in ruby