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.
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.
Sequence Chart
Data
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).
Computational Implementations
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)) 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] Cross-References
See also OEIS entries: Cf. A007953, A343644, A055642.