I have experimented a bit but havent found something that works for all four cases . the cases are :
Odd-Odd
**Odd-even
Even-Odd**
Even-Even
the highlited cases work the same because the amount of even integers in a range {2n+1,2m} is the same as in the range {2n,2m+1} ex.
R1={2,5} amount of evens : 2 namely 2,4
R2={3,6} amount of evens : 2 namely 4,6
Id be really happy if any of you can help me :)
Here's a simple one-liner: n2/2 - (n1-1)/2
Here's Ruby code that implements this. The / is integer division.
Negative examples