OFFSET
1,2
COMMENTS
A plot of a(n) for non-zero integers n in the range of (-10000, 10000) is given in LINKS.
Conjecture: a(n) != -1 for any positive or negative integer n.
LINKS
Rémy Sigrist, Table of n, a(n) for n = 1..10000
EXAMPLE
a(3) = 12 because it takes 12 steps for n = 3 to reach 1: 3 -> 10 -> -5 -> -14 -> 7 -> 22 -> -11 -> -32 -> 16 -> -8 -> 4 -> -2 -> 1.
MAPLE
a:= proc(n) option remember; `if`(n=1, 0,
1+a(`if`(n::even, -n/2, 3*n+1)))
end:
seq(a(n), n=1..69); # Alois P. Heinz, Aug 13 2025
MATHEMATICA
js[n_] := If[EvenQ[n], -n/2, 3n+1]; f[n_] := Length[ NestWhileList[js, n, # != 1 &]] - 1; Table[ f[n], {n, 69}] (* James C. McMahon, Apr 30 2025 *)
PROG
(Python)
def A383131(n):
ct = 0
while n != 1: n = 3*n+1 if n%2 else -n>>1; ct += 1
return ct
(PARI) a(n) = { for (k = 0, oo, if (n==1, return (k), n = if (n%2, 3*n+1, -n/2)); ); } \\ Rémy Sigrist, Apr 19 2025
CROSSREFS
KEYWORD
nonn
AUTHOR
Ya-Ping Lu, Apr 17 2025
STATUS
approved
