Basically, I want to write an algorithm to find out which number takes 500 iterations to reach 1. I tried some variations but couldn't get it right.
Here is my code so far:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace sequence4
{
class Program
{
static void Main(string[] args)
{
long startingNumber = 1;
long count = 0;
while (count != 500)
{
startingNumber = startingNumber * 2;
count++;
startingNumber = startingNumber / 3 - 1;
count++;
}
Console.WriteLine(count);
Console.WriteLine(startingNumber);
}
}
}
EDIT: Updated version of the code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace sequence4
{
class Program
{
static void Main(string[] args)
{
int number = 2;
int count = 0;
while (count != 500)
{
if (number % 2 == 0)
{
number = 2 * number;
count++;
}
if (number % 2 != 0)
{
number = (number / 3) - 1;
count++;
}
}
Console.WriteLine(number);
Console.WriteLine(count);
}
}
}