OFFSET
0,1
COMMENTS
If n is (d_1, d_2, ..., d_(k-1), d_k) and m is (d_1, d_2, ..., d_(k-1), (10 - d_k) mod 10) then a(n) == a(m) (mod 4).
Sum_{i=0..10^k-1} a(10^k * n + i) = 10^k * a(n) for all n >= 0 and k >= 1.
Sum_{n=0..m * 10^k - 1} a(n) = 10^k * Sum_{n=0..m-1} a(n) for all m >= 1 and k >= 0.
LINKS
Mathematics Stack Exchange, Discussion of concepts used to find nth term mathematically.
Math subreddit, Sequence mod 4 visualisation on a table.
EXAMPLE
For n=0, there are 10 2-tuples (b_1, b_2) such that |b_1 - b_2| = 0; they are (0,0), (1,1), (2,2), (3,3), (4,4), (5,5), (6,6), (7,7), (8,8), (9,9), so a(0)=10.
For n=1, there are 18 2-tuples (b_1, b_2) such that |b_1 - b_2| = 1; they are (0,1), (1,0), (1,2), (2,1), (2,3), (3,2), (3,4), (4,3), (4,5), (5,4), (5,6), (6,5), (6,7), (7,6), (7,8), (8,7), (8,9), (9,8), so a(1)=18.
For n=42, there are 20 3-tuples (b_1, b_2, b_3) such that |b_1 - b_2| = 4 and |b_2 - b_3| = 2; they are (0,4,2), (0,4,6), (1,5,3), (1,5,7), (2,6,4), (2,6,8), (3,7,9), (3,7,5), (4,0,2), (4,8,6), (5,1,3), (5,9,7), (6,2,0), (6,2,4), (7,3,1), (7,3,5), (8,4,2), (8,4,6), (9,5,3), (9,5,7), so a(42)=20.
PROG
(Python)
def a(n):
dp = [1] * 10
for c in str(n):
bdigit = int(c)
new_dp = [0] * 10
for j in range(10):
if bdigit != 0 and j + bdigit <= 9:
new_dp[j] += dp[j + bdigit]
if j - bdigit >= 0:
new_dp[j] += dp[j - bdigit]
dp = new_dp
return sum(dp)
CROSSREFS
KEYWORD
base,easy,nonn
AUTHOR
Shahrukh Jamil, Dec 26 2023
STATUS
approved