Okay, I know this is going to sound like homework; but here goes any way. I am trying to solve this problem using C#. The excerpt from the problem description is shown below:
Given an input n, it is possible to determine the number of numbers printed (including the 1). For a given n this is called the cycle-length of n. In the example above, the cycle length of 22 is 16. For any two numbers i and j you are to determine the maximum cycle length over all numbers between i and j.
Question
I understand everything except for one thing, the cycle length. I just don't understand it exactly. I find that the text is ambiguous about the definition of it. I assume, that the cycle length is how many numbers were in the sequence so lets say that the input is 10 the cycle length would be 8. But I am just not exactly sure. No code is required on your part but guidance is all I ask.
In addition, I already know how to read from standard input and output. Since the problem is in programming competition format.
My implementation of displaying the sequence of numbers giving n as input
static void collatz(ref int n)
{
if (n % 2 == 0)
{
n /= 2;
}
else
{
n = (3 * n) + 1;
}
Console.WriteLine(n);
}
static int GetCycleLength(int n)
{
if (n > 0)
{
int count = 1;
while (n != 1)
{
collatz(ref n);
count++;
}
return count;
}
else
{
return -1;
}
}
Notes
Although it is not homework, I want to treat as homework, so I put as one of the tags.