OFFSET
1,1
COMMENTS
Starting at the seed number (6) the sequence continues by subtracting, adding or multiplying by the step number (4). Subtracting gets precedence over addition which gets precedence over multiplication. The new number must be a positive integer and not previously listed. The sequence terminates if this is impossible, but for this seed (6) and step (4) the sequence is infinite.
More chaotic sequences are obtained if division is included: cf. A254873.
These sequences were first explored by Brian Kehrig, a 15-year-old student at Renert School, Calgary, Canada.
They are exceptionally nice sequences to introduce to the elementary school math classroom.
Like many Recamán sequences, this is worth listening to.
LINKS
Reinhard Zumkeller, Table of n, a(n) for n = 1..100000
EXAMPLE
a(1) = 6. a(2) = 6-4 = 2. a(3) = 2*4 = 8. a(4) = 8-4 = 4. a(5) = 4*4 = 16. a(6) = 16-4 = 12. a(7) = 12*4 = 48 ...
PROG
(Sage)
A=[6]
step=4
for i in [1..100]:
if A[i-1]-step>0 and (A[i-1]-step) not in A:
A.append(A[i-1]-step)
else:
if not((A[i-1]+step) in A):
A.append(A[i-1]+step)
else:
A.append(step*A[i-1])
A # - Tom Edgar, Feb 16 2015
(Haskell)
import Data.Set (Set, singleton, notMember, insert)
a254868 n = a254868_list !! (n-1)
a254868_list = 6 : kehrig (singleton 6) 6 where
kehrig s x | x > 4 && (x - 4) `notMember` s =
(x - 4) : kehrig (insert (x - 4) s) (x - 4)
| (x + 4) `notMember` s =
(x + 4) : kehrig (insert (x + 4) s) (x + 4)
| otherwise =
(x * 4) : kehrig (insert (x * 4) s) (x * 4)
-- Reinhard Zumkeller, Feb 25 2015
(Python)
from sympy import primerange, prime
def aupton(nn, seed=6, step=4):
alst, step = [seed], step
for n in range(1, nn+1, 1):
x, y, z = alst[-1] - step, alst[-1] + step, alst[-1] * step
if x > 0 and x not in alst: alst.append(x)
elif y > 0 and y not in alst: alst.append(y)
elif z > 0 and z not in alst: alst.append(z)
else: break
return alst
print(aupton(57)) # Michael S. Branicky, Jun 02 2021
CROSSREFS
KEYWORD
AUTHOR
Gordon Hamilton, Feb 09 2015
STATUS
approved