A336914 Number of steps to reach 1 in '3^x+1' problem (a variation of the Collatz problem), or -1 if 1 is never reached.
0, 1, 4, 2, 11, 2, 9, 5, 7, 5, 7, 5, 5, 5, 16, 3, 5, 3, 5, 3, 16, 3, 14, 3, 9, 3, 14, 3, 9, 3, 9, 12, 14, 12, 22, 12, 14, 12, 7, 12, 5, 12, 5, 12, 7, 12, 5, 12, 7, 12, 5, 12, 5, 12, 20, 12, 5, 12, 16, 12, 5, 12, 14, 3, 12, 3, 5, 3, 14, 3, 5, 3, 14, 3, 5, 3, 5
Offset: 1
Keywords
Examples
For n = 5, a(5) = 11, because there are 11 steps from 5 to 1 in the following trajectory for 5: 5, 244, 7, 2188, 11, 177148, 17, 129140164, 26, 4, 2, 1. For n = 6, a(6) = 2, because there are 2 steps from 6 to 1 in the following trajectory for 6: 6, 2, 1.
Links
- Wikipedia, Collatz conjecture
Crossrefs
Programs
-
Python
from math import floor, log def a(n): if n == 1: return 0 count = 0 while True: if n % 2: n = 3**n + 1 else: n = int(floor(log(n, 2))) count += 1 if n == 1: break return count print([a(n) for n in range(1, 101)])
Comments