solved problem 44 in ruby