/*
   Program to test the Collatz Conjecture for various numbers.
   https://en.wikipedia.org/wiki/Collatz_conjecture
   
   Start from some specified n
   
   Repeat rule: if n is even n = n/2
                        else n = 3n+1
                 
   Conjecture: Will the sequence always reach n=1 after enough iterations? YES. 
   
   Try changing the program so you run through n=1,..,100000 and for each n output the count.
   
   Make a plot of (n, count).
*/

#include <iostream>
using namespace std;

int main()
{
   int n;
   cout << "Please state starting number:";
   cin >> n;

   int count=0;
   while (n!=1)
      {
        bool isEven = (n%2==0);   // no rest when division by 2, then its integer
        
        if (isEven) n/=2;         // same as n=n/2 which is OK for even numbers
               else n=3*n+1;

        cout << n << " ";
        count++;
      }
  
   cout << " Finally hit 1 after " << count << " steps" << endl;
   return 0;
}
