this does seem to work, but part of me wonders if there is a could improve it, the masks are essentially used to store the indexes for the array the maximum array len is int size -1, we are only allowed to use #include <stdio.h> and no other headers
int sum_up_smart(int number_array[],int array_len, int mask, int prev_mask,int sum)
{
const int dif = mask ^ prev_mask;
if (dif==0)
{
return sum;
}
const int add_mask = mask & dif; //ones in here now represent indexes that need to be added
const int remove_mask = prev_mask & dif; //ones in here now represent indexes that need to be removed
for (size_t i = 0; i < array_len; i++)
{
if ((add_mask & (1 << i)) != 0)
{
sum += number_array[i];
}
else if ((remove_mask & (1 << i)) != 0)
{
sum -= number_array[i];
}
}
return sum;
}```