//
// The 3n + 1 problem
//

collatz = function(start)
{
  local(c, n);
  c = n = start;

  while(n > 1)
  {
    if(mod(n,2) == 0) {
      n = n/2;
    else
      n = 3*n + 1;
    }
    c = [c, n];
  }
  return c;
};

//
// Try it out
//
 c = collatz(100);

 plgrid ();
 pltitle ( "RLaB Collatz Example" );
 xlabel ( "Indeplendent Variable" );
 ylabel ( "Deplendent Variable" );
 plot( [1:c.nc; c]' );
 pause ();
 plgrid ( ,"bcgnstlv");
 plot( [1:c.nc; c]' );
