This is for Project Euler, issue 8.
I am trying to foreach through an array of numbers, each time skipping the last number and pulling out the next 13 neighboring numbers in the array.
My code is:
for(int x = 0; x < 987; x++) { foreach(int number in numbers.Take(13).Skip(x)) { hold = hold * number; adjacent[index] = number; index++; } if (hold > product) { product = hold; } Array.Clear(adjacent, 0, adjacent.Length); index = 0; hold = 1; }
The problem I am facing is that every time it enumerates through an array, it subtracts the amount equal to x from the number of times it goes through the list, which is 13.
So, when x is 5, it goes through the array 8 times.
How can I fix this when it moves 13 numbers at a time?
c # foreach linq
Ryan rockers
source share