// $Header: /usr/local/cvsroot/courses/cs236/samplecode/3x+1.cpp,v 1.1 2007/01/31 21:45:46 neffr Exp $
#include <iostream>
#include <cstdlib>
using namespace std;

unsigned long threeXplusOne(unsigned long x)
{
   if (x % 2 == 0)
   {
      //cout << x << " is even, so divide by 2:\n";
      return x / 2;
   }
   else
   {
      //cout << x << " is odd, so multiply by 3 and add 1:\n";
      unsigned long result = x * 3 + 1;
      if (result < x)
      {
         cout << " Oops, overflow, result is < " << x << endl;
         cout << " RESULT = " << result << endl;
      }
      return result;
   }
}

bool testConjecture(unsigned long x)
{
   unsigned long result = x;
   int count;
   
   while (result != 1)
   {
      result = threeXplusOne(result);
      count++;
   }
   cout << "," << result;
   cout << "," << count << endl;
   
   return (result == 1);
}

int main()//int argc, const char* argv[])
{
//    if (argc < 2)
//    {
//       cerr << "Usage: " << argv[0] << " n\n";
//       return 1;
//    }
//    else
//    {
//       return testConjecture(atol(argv[1]));
      
//    }
   for (unsigned long i = 2; i <= 100000; i++)
   {
      cout << i;
      testConjecture(i);
      
   }
}
