function hail2 ( n )

%% HAIL2 computes all the hailstone numbers at the same time.
%
  tic

  x = linspace ( 1, n, n );
  y = x;
  z = zeros ( n, 1 );

  while ( any ( y ~= 1 ) )
    i = find ( y ~= 1 && mod ( y, 2 ) == 0 );
    j = find ( y ~= 1 && mod ( y, 2 ) == 1 );
    y(i) = y(i) / 2;
    y(j) = 3 * y(j) + 1; 
    z(i) = z(i) + 1;
    z(j) = z(j) + 1;
  end

  figure ( 2 )
  plot ( x, z, 'm*' )
  title ( 'HAIL2' )

  toc

  return
end
