A336830 The Sydney Opera House sequence: a(0) = 0, a(1) = 1; for n > 0, a(n) = min(a(n-1)/n if n|a(n-1), a(n-1)-n) where a(n) is nonnegative and not already in the sequence. Otherwise a(n) = min(a(n-1)+n, a(n-1)*n) where a(n) is not already in the sequence. Otherwise a(n) = a(n-1) + n.
0, 1, 2, 5, 9, 4, 10, 3, 11, 20, 30, 19, 7, 91, 77, 62, 46, 29, 47, 28, 8, 168, 146, 123, 99, 74, 48, 21, 49, 78, 108, 139, 107, 140, 106, 71, 35, 72, 34, 73, 33, 1353, 1311, 1268, 1224, 1179, 1133, 1086, 1038, 989, 939, 888, 836, 783, 729, 674, 618, 561, 503, 444, 384, 323, 261
Offset: 0
Keywords
Examples
a(2) = 2. As a(1) = 1, which is not divisible by 2 nor greater than 2, a(2) must be the minimum of 1*2=2 and 1+2=3, so multiplication is chosen. a(5) = 4. As a(4) = 9, which is not divisible by 5, and 4 has not appeared previously in the sequence, a(5) = a(4)-5 = 9-5 = 4. a(82) = 52. As a(81) = 4264 one candidate is 4264-82 = 4182. However 82|4264 and 4264/82 = 52. Neither of these candidates has previously appeared in the sequence, but 52 is the minimum of the two. This is the first time a division operation is used for a(n).
Links
- Michael S. Branicky, Table of n, a(n) for n = 0..20000
- Scott R. Shannon, Line graph of the first 10 million terms.
- Index entries for sequences related to Recamán's sequence
Programs
-
Python
global arr arr = [] def a(n): # Case 1 if n == 0: return 0 a_prev = arr[-1] cand = [] # Case 2 x = a_prev - n y = a_prev / n if x > 0 and not x in arr: cand.append(x) if y == int(y) and not y in arr: cand.append(y) if cand != []: return min(cand) # Case 3 cand = [] x = a_prev + n y = a_prev * n if not x in arr: cand.append(x) if not y in arr: cand.append(y) if cand != []: return min(cand) # Case 4 return a_prev + n def seq(n): for i in range(n): print("{}, ".format(a(i)), end="") arr.append(a(i)) seq(60) # Christoph B. Kassir, Apr 08 2022
-
Python
from itertools import count, islice def A336830(): # generator of terms aset, an, oo = {0, 1}, 1, float('inf') yield from [0, 1] for n in count(2): v1, v2 = an - n if an >= n else oo, an//n if an%n == 0 else oo v = min((vi for vi in [v1, v2] if vi not in aset), default=oo) if v != oo: an = v else: v3, v4 = an+n, an*n v = min((vi for vi in [v3, v4] if vi not in aset), default=oo) if v != oo: an = v else: an = an+n yield an aset.add(an) print(list(islice(A336830(), 60))) # Michael S. Branicky, Apr 15 2023
Comments