Good afternoon guys, I have a following problem of the school to solve, being it in relation to Collatz Problem, where I need to develop an application that will find out the starting number between 1 and 1 million that produces the largest sequence.
I made the following code without applying LINQ, and would like to know how to use linq in this situation.
var sequence_size = 0;
var best_number = 0;
var sequence = 0;
for (var i = 0; i <= 1000000; i ++)
{
var size_ = 1;
sequence = i;
while (sequence! = 1)
{
sequence = sequence% 2 == 0? sequence / 2: sequence * 3 + 1;
size ++;
}
if (size> size)
{
size_sequence = size;
best_number = i;
}
}