Jelly, 10 bytes
ÆfḊPạμÐL·i2
Try it online! or verify most test cases. The last test cases finishes quickly locally.
How it works
ÆfḊPạμÐL·i2 Main link. Argument: n (integer)
Æf Factorize n, yielding a list of primes, [] for 1, or [0] for 0.
Ḋ Dequeue; remove the first (smallest) element.
P Take the product.
This yields the largest proper divisor if n > 1, 1 if n < 2.
ạ Yield the abs. value of the difference of the divisor (or 1) and n.
μ Convert the chain to the left into a link.
ÐL· Repeatedly execute the link until the results are no longer unique.
Collect all intermediate results in a list.
For each starting value of n, the last results are 2 -> 1 -> 0 (-> 1).
i2 Compute the 1-based index of 2.
Jelly, 10 bytes
ÆfḊPạμÐL·i2
Try it online! or verify most test cases. The last test cases finishes quickly locally.
Jelly, 10 bytes
ÆfḊPạμÐL·i2
Try it online! or verify most test cases. The last test cases finishes quickly locally.
How it works
ÆfḊPạμÐL·i2 Main link. Argument: n (integer)
Æf Factorize n, yielding a list of primes, [] for 1, or [0] for 0.
Ḋ Dequeue; remove the first (smallest) element.
P Take the product.
This yields the largest proper divisor if n > 1, 1 if n < 2.
ạ Yield the abs. value of the difference of the divisor (or 1) and n.
μ Convert the chain to the left into a link.
ÐL· Repeatedly execute the link until the results are no longer unique.
Collect all intermediate results in a list.
For each starting value of n, the last results are 2 -> 1 -> 0 (-> 1).
i2 Compute the 1-based index of 2.
Jelly, 10 bytes
ÆfḊPạμÐL·i2
Try it online! or verify most test cases. The last test cases finishes quickly locally.