A304030 a(n) is the number of steps at which the Collatz ('3x+1') trajectory of n crosses its initial value, or -1 if the number of crossings is infinite.
0, 0, 1, 0, 1, 4, 3, 0, 5, 2, 3, 2, 3, 8, 3, 0, 3, 10, 7, 0, 1, 6, 1, 0, 9, 2, 3, 6, 7, 4, 3, 0, 13, 4, 1, 4, 5, 8, 9, 0, 7, 2, 5, 2, 3, 4, 5, 0, 5, 8, 5, 0, 1, 14, 9, 0, 7, 2, 3, 6, 7, 12, 9, 0, 5, 6, 3, 0, 1, 4, 7, 0, 13, 2, 1, 2, 3, 8, 3, 0, 7, 14, 11, 0, 1, 8, 3, 0, 3, 2, 7, 4, 5, 12, 9, 0, 19, 4, 1, 0
Offset: 1
Keywords
Examples
The Collatz trajectory of 6 crosses its initial value (6) a total of 4 times, so a(6) = 4: . 16 / \ / \ 10 / \ / \ / \ / \ / 8 6---------*-----*---*-----------*-------- \ / \ / \ \ / 5 \ \ / \ \ / 4 3 \ ... (Each "*" represents a crossing.)
Links
Programs
-
Mathematica
Collatz[n_] := NestWhileList[ If[ OddQ@#, 3# +1, #/2] &, n, # > 1 &]; f[n_] := Block[{x = Length[ SplitBy[ Collatz@ n, # < n +1 &]] - 1}, If[ OddQ@ n && n > 1, x - 1, x]]; Array[f, 100] (* Robert G. Wilson v, May 05 2018 *)
-
Python
def A304030(n): prevc = c = n h = 0 while c > 1: if c % 2: c = 3*c+1 if prevc < n and c > n: h += 1 else: c //= 2 if prevc > n and c < n: h += 1 prevc = c return h print([A304030(n) for n in range(1, 100)]) # Paolo Xausa, Feb 22 2022
Comments