0
$\begingroup$

I was going through this website where I found 3n + 1 problem.

I was not able to understand what the output should be.

I understood if the input is 1 and 10 then the numbers between 1 to 10 need to be in consideration, and the output will be 20. But I am wondering how it can be 20.

Where as 10 - 10 5 16 8 4 2 1. (Total 6 excluding 16). Then how can be it 20?

Please could you please help me.

Please make me understand the problem, What it really wants me to solve?

Please tell me if I had put some wrong tag

$\endgroup$
6
$\begingroup$

If the input is $i=1$ and $j=10$ then you need to consider the full cycle for each starting value $i=1\le n \le 10=j$, consider all of their "cycle lengths" and return the largest cycle length.

For $n=10$ the cycle length is 7, since you need to include 16.

Given $i=1,j=10$ as input, the cycle length for $n=1$ is $1$, for $n=2$ is 2, for $n=3$ is $8$, and for $n=4,5,6,7,8,9,10$ is respectively $3,6,9,17,4,20,7$. The largest value in this range is 20, which should be your answer.

Similarly, if $i=100,j=200$, then the longest cycle length is $125$ which you find starting with $n=171$ then considering the full cycle $C=\{171,514,257,772,\ldots,4,2,1\},\vert C\vert=125$.

$\endgroup$
  • $\begingroup$ There's some confusing nonstandard terminology involved here. It looks like the exercise is asking for the length of the sequence from the starting number to the first 1. But that sequence is not a "cycle" -- the only known cycle is $1\mapsto 4\mapsto 2\mapsto 1$ of length 3. $\endgroup$ – hmakholm left over Monica Jun 28 '12 at 12:52
  • $\begingroup$ @Zander: Thanks a lot, for making me understand... $\endgroup$ – Rasmi Ranjan Nayak Jun 28 '12 at 13:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.