I want to populate an array of size n like this (a very big array):
1 for i = 1, (n/2)+1
2 for i = 2, 3, ... , (n/2)
0 for i = (n/2)+2, ... , n
Is the fastest way iterating through 0 to n and using an if statement and % for each one?
Like this:
array = []
for index in range(1,n):
if index == 1 or (index % ((n/2)+1) == 0):
array.append(1)
if index == 2 or index == 3 or (index % (n/2) == 0):
array.append(2)
if (index % ((n/2)+2) == 0):
array.append(0)
I have tried to think of other ways to do this but I have not come up with anything. I'm not a programmer by trade but I am not sure how else I would implement this.