solved problem 1 in ruby