So we all heard of the story of Gauss and the sum(1 to 100); whereas the equation for figuring out the sum of any consecutive integer is sum = (n/2)(first + last); whereas if the first number is a non-zero integer the n = (last - first) + 1
For example:
The sum of consecutive numbers from an arbitrary 237 to an arbitrary 796 can be easily found by
1. n = (796 - 237) + 1 = 560
2. (560/2)(237+796) = 289,240.
However, how would this formula be expressed mathematically if we are trying to find the sum of all the even/odd numbers in a consecutive set?
1. The first challenge is figuring out "nodd" or "neven"
For example, a number set [4 to 9] includes 3 evens [4, 6, 8] and 3 odds [5, 7, 9]. This means "nodd" can be expressed as n/2, or in other words
nodd = ((last - first) + 1) / 2.
However, if the set of numbers is [4 to 8], then it includes 3 evens [ 4, 6, 8] and 2 odds [5, 7] then this equation fails, as n = 5 but nodd = 2, and 2 =/= 3.
So how do we express this mathematically, so that an arbitrary range of numbers can easily be counted?
For example:
The sum of consecutive numbers from an arbitrary 237 to an arbitrary 796 can be easily found by
1. n = (796 - 237) + 1 = 560
2. (560/2)(237+796) = 289,240.
However, how would this formula be expressed mathematically if we are trying to find the sum of all the even/odd numbers in a consecutive set?
1. The first challenge is figuring out "nodd" or "neven"
For example, a number set [4 to 9] includes 3 evens [4, 6, 8] and 3 odds [5, 7, 9]. This means "nodd" can be expressed as n/2, or in other words
nodd = ((last - first) + 1) / 2.
However, if the set of numbers is [4 to 8], then it includes 3 evens [ 4, 6, 8] and 2 odds [5, 7] then this equation fails, as n = 5 but nodd = 2, and 2 =/= 3.
So how do we express this mathematically, so that an arbitrary range of numbers can easily be counted?