A333307 Lexicographically earliest sequence over {0,1,2} that has the shortest palindromic or square subsequence (see Comments for precise definition).
0, 1, 2, 0, 1, 1, 2, 0, 0, 1, 2, 0, 1, 1, 2, 2, 0, 1, 2, 0, 0, 1, 2, 2, 0, 1, 2, 0, 2, 2, 1, 0, 2, 1, 1, 0, 2, 2, 1, 0, 2, 1, 2, 2, 0, 1, 2, 0, 0, 1, 2, 2, 0, 1, 2, 0, 2, 2, 1, 0, 2, 1, 1, 0, 2, 2, 1, 0, 0, 2, 1, 0, 2, 2, 1, 0, 0, 0, 2, 1, 0, 2
Offset: 0
Keywords
Examples
a(5) = 1: 0 yields a palindromic subsequence of length 3: [0, 1, 0], 1 a square subsequence of length 2: [1, 1], and 2 a square subsequence of length 6: [0, 1, 2, 0, 1, 2]. a(6) = 2: 0 yields a palindromic subsequence of length 4: [0, 1, 1, 0], 1 a palindromic subsequence of length 3: [1, 1, 1], and 2 a palindromic subsequence of length 1: [2]
Programs
-
Python
def a333307(n): seq = [] for k in range(n): options = [] l = len(seq) + 1 for m in range(3): # base palindrome, square = 0, 0 for i in range(l - 1): # palindrome if seq[i::] + [m] == (seq[i::] + [m])[::-1]: palindrome = l - i break for i in range(l // 2, -1, -1): # square if seq[l - 2 * i: l - i] == seq[l - i:] + [m]: square = 2 * i break options.append(max(palindrome, square)) seq.append(options.index(min(options))) return seq print(a333307(82))
Comments