%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This is a companion file for the paper 
% "Combinatorial properties of triangular partitions" by Sergi Elizalde and Alejandro B. Galvan, 2023.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% The MATLAB code below computes the number of triangular partitions with two
% removable cells of size n for 1 <= n <= nmax and plots them.

n_max = 40;
trcp = zeros(1, n_max);     % trcp(n) := number of partitions of this type of size n.
for a = 1 : n_max
    for b = 1 : n_max
        if gcd(a, b) == 1
            for j = 0 : a - 1
                for i = 0 : b - 1
                    for k = 2 : n_max
                        % Size function:
                        n = (k - 1)*((a + 1)*(b + 1)/2 - 1) + (k - 1)*(k - 2)*a*b/2 + i*j + i*(k - 1)*a + j*(k - 1)*b + trcp_aux(a, b, j) + trcp_aux(b, a, i) + k;
                        if n <= n_max && n > 0
                            trcp(n) = trcp(n) + 1;
                        end
                    end
                end
            end
        end
    end
end

figure()
plot([1:n_max], trcp)

% Auxiliary function used in the size function:
function aux = trcp_aux(a, b, j)
    aux = 0;
    for r = 1 : j
        aux = aux + floor(r*b/a) + 1;
    end
end