solve problem 2 with ruby