Duc Phan's Project Euler solution in Ruby