Euler 78 attempt 2 - refactored