login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A343383 Length of the preperiodic part of 'Roll and Subtract' trajectory of n. 1
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 6, 4, 5, 3, 3, 5, 4, 6, 2, 1, 2, 6, 4, 5, 3, 3, 5, 4, 6, 2, 1, 2, 6, 4, 5, 3, 3, 5, 4, 6, 2, 1, 2, 6, 4, 5, 3, 3, 5, 4, 6, 2, 1, 2, 6, 4, 5, 3, 3, 5, 4, 6, 2, 1, 2, 6, 4, 5, 3, 3, 5, 4, 6, 2, 1, 2, 6, 4, 5, 3, 3, 5, 4, 6 (list; graph; refs; listen; history; text; internal format)
OFFSET
0,11
COMMENTS
'Roll and Subtract' is defined by x -> |x - roll(x)|, where roll(x) takes the first digit of a number and moves it to the back (rolls it around to the back).
Differs from A151962 first at n=101. - R. J. Mathar, May 07 2021
LINKS
EXAMPLE
a(119) = 4 since |119 - 191| = 72 -> |72 - 27| = 45 -> |45 - 54| = 9 -> |9 - 9| = 0. The value a(0) maps to 0, so the sequence ends there after 4 values have been traversed.
a(12737) = 1 since |12737 - 27371| = 14634 -> |14634 - 46341| = 31707 -> |31707 - 17073| = 14634. Since 14634 is already in the sequence, the sequence ends there.
MATHEMATICA
Array[Function[w, LengthWhile[w, # != Last[w] &]]@ NestWhileList[Abs[# - FromDigits@ RotateLeft@ IntegerDigits[#]] &, #, Unequal, All] &, 105, 0] (* Michael De Vlieger, Apr 13 2021 *)
PROG
(Python)
def roll(n):
""" Moves first digit to the back """
s = str(n)
return int(s[1:] + s[0])
def backtrack(past, length, offset, dct):
""" Goes through every value passed and adds it and it's length to the dictionary """
if length == 0:
for elem in past:
dct[elem] = 0
i = 0
while length > 0:
n = past[i]
dct[n] = length + offset
i += 1
length -= 1
return dct
def a(n, dct):
past = []
length = 0
while (n not in dct):
past.append(n)
length += 1
n = abs(n - roll(n))
if n in past: # For duplicates
length = past.index(n)
dct = backtrack(past, length, 0, dct)
return dct, length
offset = dct[n]
dct = backtrack(past, length, offset, dct)
length += offset
return dct, length
dct = {}
sequence = []
i = 1
while i < 1000:
out = a(i, dct)
dct = out[0]
sequence.append(out[1])
i += 1
CROSSREFS
Cf. A072137 (reverse and subtract).
Sequence in context: A174959 A126093 A065279 * A151962 A072137 A061569
KEYWORD
nonn,base
AUTHOR
Jonathon Priestley, Apr 12 2021
STATUS
approved

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified April 18 20:26 EDT 2024. Contains 371781 sequences. (Running on oeis4.)