function symbol = card_symbol ( n )

%*****************************************************************************80
%
%% card_symbol() is given the index of a card and returns its symbol.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    15 April 2022
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N: the card index.  1 <= index <= 52.
%
%  Output:
%
%    string SYMBOL: the card rank and suit, as in '5H' or '10C' or 'QD'.
%

%
%  I had to fumble may way through MATLAB's awkward treatment of strings...
%
  r = mod ( abs ( n ) - 1, 13 ) + 1;
  rank_symbol1 = [ ...
    ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ' ];
  rs1 = rank_symbol1 ( r );
  rank_symbol2 = [ ...
    'A', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'J', 'Q', 'K' ];
  rs2 =  rank_symbol2 ( r );

  suit_index = floor ( ( abs ( n ) - 1 ) / 13 ) + 1;
  suits = [ 'H', 'C', 'D', 'S' ];
  suit = suits(suit_index);

  faceup = ( 0 < n );

  if ( faceup )
    symbol = sprintf ( ' %s%s%s ', rs1, rs2, suit );
  else
    symbol = sprintf ( '[%s%s%s]', rs1, rs2, suit );
  end

  return
end

