Wednesday, May 20, 2026

Contribution to the OEIS - A395743

 A395743

Sum of the cumulative number of previous occurrences of the digits of n in the sequence 1..n excluding the current occurrence of each digit.
0
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 5, 5, 6, 7, 8, 9, 10, 11, 12, 3, 15, 9, 8, 9, 10, 11, 12, 13, 14, 5, 17, 18, 13, 11, 12, 13, 14, 15, 16, 7, 19, 20, 21, 17, 14, 15, 16, 17, 18, 9, 21, 22, 23, 24, 21, 17, 18, 19, 20, 11, 23, 24, 25, 26, 27, 25, 20, 21, 22, 13
OFFSET
1,11
COMMENTS
This sequence is the exclusive counterpart to A343644. While A343644 counts the occurrences of digits in the range [1,n], a(n) counts only the occurrences strictly preceding each digit of n. Formally a(n) = A343644(n) - A055642(n). Thus, this sequence represents the exclusive scan of digit occurrences, whereas A343644 is the inclusive scan. a(n) = 0 for all single-digit n as it measures the cumulative repetition of digits at the exact moment n is formed.
FORMULA
a(n) = Sum_{i=1..k} C(d_i), where d_1, d_2, ..., d_k are the digits of n, and C(d_i) is the number of times digit d_i has appeared in the concatenation of all integers from 1 to n-1 plus the digits of n to the left of d_i.
a(n) = A343644(n) - A055642(n).
EXAMPLE
For n = 11:
The digits are '1' and '1'.
- First '1': Appeared previously in {1, 10} -> count = 2.
- Second '1': Appeared previously in {1, 10} AND as the first digit of 11 -> count = 3.
a(11) = 2 + 3 = 5.
For n = 12:
The digits are '1' and '2'.
- Digit '1': Appeared in {1, 10, 11 (twice)} -> count = 4.
- Digit '2': Appeared in {2} -> count = 1.
a(12) = 4 + 1 = 5.
MATHEMATICA
a[n_]:=Module[{sm=0, id=IntegerDigits[n], d=IntegerDigits/@Range[n-1]//Flatten}, Do[sm=sm+Count[Join[d, Take[id, i-1]], id[[i]]], {i, IntegerLength[n]}]; sm]; Array[a, 70]
PROG
(Python)
def generate_sequence(limit):
seq = []
counts = [0] * 10
for n in range(1, limit + 1):
v = 0
s = str(n)
for char in s:
d = ord(char) - 48
v += counts[d]
counts[d] += 1
seq.append(v)
return seq
print(generate_sequence(70))
CROSSREFS
KEYWORD
nonn,base,easy,new
AUTHOR
STATUS
approved

No comments:

Post a Comment

An Open Message to the Blog's Fans in Singapore

(Image:  Free 12 singapore icons - Iconfinder ) This past week, more views of this blog were made from Singapore than other country. To ackn...

Popular in last 30 days