Solution to project euler