% Generate a list C of all Roman numerals from 1 to 3999

% List-of-lists: for each power of 10, list the codes for each digit
digits = { {'', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'}; % 1s
           {'', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC'}; % 10s
           {'', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM'}; % 100s
           {'', 'M', 'MM', 'MMM'} }; % 1000s

% Loop over all digits for each power of 10
for d3 = 0:3
   for d2 = 0:9
      for d1 = 0:9
         for d0 = 0:9
            % Assemble our number (also our index)
            n = d3*10^3 + d2*10^2 + d1*10^1 + d0*10^0;

            % No Roman numeral for 0 (and no cell array index of 0)
            if n > 0
                % Concatenate digit codes to form string
                C{n} = [ digits{4}{d3+1} digits{3}{d2+1} digits{2}{d1+1} digits{1}{d0+1} ];
            end
         end
      end
   end
end
