% hailstone.m
%
%  Compute the Collatz sequence for a positive integer N,
%  and report the number of steps required to reach 1.
%
n = input ( '  Enter a positive number N: ' );
i = 0;

n_save = n;  % We SAVE a copy of N, so we can report it at the end.

while ( 1 < n )

  i = i + 1;

  if ( mod ( n, 2 ) == 0 )
    n = n / 2;
  else
    n = 3 * n + 1;
  end

end

fprintf ( '  Height(%d) = %d\n', n_save, i );
