A380317 The lexicographically earliest sequence of positive numbers which is identical to the run lengths of its first differences.
1, 1, 2, 2, 2, 3, 4, 3, 2, 2, 2, 2, 3, 4, 5, 6, 5, 4, 3, 3, 3, 2, 1, 1, 1, 2, 3, 3, 3, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 2, 2, 2, 2, 2, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 3, 3, 3, 4, 5, 6, 5, 4, 3, 3, 3, 1, 1, 2, 2, 2, 3, 4, 5, 4, 3, 2, 2, 2, 2, 3, 4, 5, 4, 3, 2, 1, 1
Offset: 1
Examples
The sequence of first differences (where the n-th term is a(n+1)-a(n)) is: 0, 1, 0, 0, 1, 1, -1, -1, 0, 0, 0, 1, 1, 1, 1, -1, -1, -1, 0, 0, ... The run lengths of consecutive values are: 1, 1, 2, 2, 2, 3, 4, 3, 2, ... Which is the original sequence.
Links
- Dominic McCarty, Table of n, a(n) for n = 1..10000
Programs
-
Python
from itertools import groupby def runs(l): return [len(list(group)) for i, group in groupby(l)] def firstDifs(l): return [l[i]-l[i-1] for i in range(1,len(l))] a = [1,1] while len(runs(firstDifs(a))) <= 100: a.append(1) b, m = runs(firstDifs(a)), max(firstDifs(a)) while not (all(b[n] == a[n] for n in range(len(b)-1)) and b[-1] <= a[len(b)-1]): a[-1] += 1 if a[-1] > m+a[-2]+1: a.pop(); a[-1] += 1 #Backtracking needed b = runs(firstDifs(a)) print(a[:len(runs(firstDifs(a)))])
Comments