solution to project euler problem 9; ruby