function A = president_matrix ( )

%*****************************************************************************80
%
%% president_matrix() returns a sort of presidential "adjacency" matrix.
%
%  Discussion:
%
%    Presidents I and J are "adjacent" if there was any year in which 
%    they were both alive, that is, if their lifespans overlap.
%
%    To keep things simple, we concentrate solely on birth and death years,
%    without worrying more precisely about month and day.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    05 May 2026
%
%  Author:
%
%    John Burkardt
%
%  Output:
%
%    integer A(pres_num,pres_num): A(i,j) is 1 if presidents #i and #j 
%    have overlapping lifespans.  Otherwise, the entry is 0.
%    This defines a sort of graph adjacency matrix.
%

%
%  Year of birth for each president.
%
  b = [ ...
    1732, 1735, 1743, 1751, 1758, 1767, 1767, 1782, ...
    1773, 1790, 1795, 1784, 1800, 1804, 1791, 1809, ...
    1808, 1822, 1822, 1831, 1829, 1837, 1833, 1837, ...
    1843, 1858, 1857, 1856, 1865, 1872, 1874, 1882, ...
    1884, 1890, 1917, 1908, 1913, 1913, 1924, 1911, ...
    1924, 1946, 1946, 1961, 1946, 1942, 1946 ];
%
%  Year of death for each president.
%  Currently nondead presidents are given a nominal death date.
%
  d = [ ...
    1799, 1826, 1826, 1836, 1831, 1848, 1845, 1862, ...
    1841, 1862, 1849, 1850, 1874, 1869, 1868, 1865, ...
    1875, 1885, 1893, 1881, 1886, 1908, 1901, 1908, ...
    1901, 1919, 1930, 1924, 1923, 1933, 1964, 1945, ...
    1972, 1969, 1963, 1973, 1994, 2006, 2024, 2004, ...
    2018, 2050, 2050, 2050, 2050, 2050, 2050 ];

  pres_num = length ( b );
%
%  Define the adjacency matrix.
%  We use strict inequalities here to guarantee overlap.
%
  A = zeros ( pres_num, pres_num );

  for pres_i = 1 : pres_num
    for pres_j = 1 : pres_num
      if ( b(pres_i) < d(pres_j) && b(pres_j) < d(pres_i) )
        A(pres_i,pres_j) = 1;
      end
    end
  end

  return
end

