So I have an increasing sequence of numbers from 2 to N (any integer > 1).
For N = 300
2,3,4,5, ..., 297,298,299,300
I have to calculate the sum of absolute difference between even and odd digits (not indexes) for each integer in a given sequence.
For example:
- 2344798 its will be |(2+4+4+8) - (3+7+9)| = 5
- 28 = |(2+8) - 0| = 10
- 1002 = |(2+0+0)-1| = 1
I am trying to come up with some formula but I not able to.
Adding more: For N = 300 sequence will be:
2,3,4, ..., 298, 299, 300
Answer: |2-0| + |0-3| + |4-0| + .....+ |(2+8)-9| + |2 -(9+9)| + |0 - 3|
This is a tricky function, I doubt there's a simple formula. Some intriguing patterns arise if you look at $n$ mod 9, although it's easier to see those patterns using mod 18. The cumulative sum over a sequence of integers may be a little more well-behaved; it would be fairly easy to calculate if it weren't for that pesky absolute value.
FWIW, here's a table of values, using rows of 18 that I created using Python.
And here's the Python code I used.