Find the missing number in a sequence

advertisements

I need to find one missing number, from a sequence of numbers

such as

4 8 12 16 __ 24.

I need to find the missing number. How would I do that programmatically?

the numbers and the missing placement are not static, so they should be able to change.

Hope it is possible.


You could use some silly linq like this silly example :)

var numbers = new List<int>{4, 8, 12, 16, 24, 28, 36};
int first = numbers.First();
int last = numbers.Last();

var missing = Enumerable.Range(first, last).Where(n => n % first == 0).Except(numbers);

Returns:
20
32

-Bracing self for downvotes-