I am working on Problem 14 on Project Euler, and my code seems to freeze at random intervals for no apparent reason.
static void Main()
{
int maxNum = 0;
int maxLength = 0;
for (int x = 2; x < 1000000; ++x)
{
int num = x;
int length = 0;
while (num != 1)
{
if (num % 2 == 0)
{
num /= 2;
length++;
}
else
{
num = (3 * num) + 1;
length++;
}
}
if (length > maxLength)
{
maxLength = length;
maxNum = x;
}
}
Console.WriteLine(maxNum);
Console.ReadLine();
The number that the program hangs at is different each time I run it and doesn't seem to follow any set patterns. Any ideas on why it would be hanging like this? Thanks in advance.