% hail_sequence.m
%  Compute the Collatz sequence for a positive integer N.
%
i = 0;

while ( 1 < n )

  if ( i == 0 )
    n = input ( '  Enter a starting value for Collatz sequence: ' );
  else
    if ( mod ( n, 2 ) == 0 )
      n = n / 2;
    else
      n = 3 * n + 1;
    end
  end

  fprintf ( ' %d', n );
  i = i + 1;

end
fprintf ( '\n' );
fprintf ( 'We took %d steps\n', i );
