% hail_length.m
%  Compute the length of 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: ' );
    n_save = n;
  else
    if ( mod ( n, 2 ) == 0 )
      n = n / 2;
    else
      n = 3 * n + 1;
    end
  end

  i = i + 1;

end
fprintf ( '  Collatz sequence for %d has length %d\n', n_save, i );

