solve problem 1 with ruby