% hail_5np1.m
%  Compute the 5n+1 sequence for a positive integer N.
%
i = 0;

while ( 1 < n )

  if ( i == 0 )
    n = input ( '  Enter a starting value for the 5n+1 sequence: ' );
    imax = input ( '  Enter a maximum number of steps: ' );
  else
    if ( mod ( n, 2 ) == 0 )
      n = n / 2;
    else
      n = 5 * n + 1;
    end
  end

  fprintf ( ' %d', n );
  i = i + 1;
  if ( imax < i )
    fprintf ( '\n' );
    fprintf ( 'BREAK!  Exceeded step limit.\n' );
    break;
  end

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