Setup¶

In [1]:
from math import ceil as mC
from math import floor as mF
from math import log as mL
import matplotlib.pyplot as plt
import seaborn as sns

Constants and Functions¶

In [2]:
def getAllHeats(n):
    
    """
    Creates all minimum heat level sets of N that can generate all heat levels from 1 to n.

    Parameters:
    none
    
    Returns:
    heats - List of all ordered N-tuples that satisfy obtaining all values of heats.
    """
    
    
    def addOnHeats(N, heats, p) :
        
        """
        Recursive function that adds one more viable heat level to all sets thus far.

        Parameters:7
        N - Final number of elements.
        heats - Set of all heats.
        p - Current number of elements in each heat set.

        Returns:
        heats - List of all ordered tuples thus far.
        """
        #As long as the last spice is not being added...
        if p < N-1 :
            new_heats = []
            for h in heats :
                #The minimum heat level to be added must be at least the previous level.
                minimum = h[-1]
                if p >= 2 :
                    #If the previous two levels are the same, the minimum heat level to be added must be at least one more.
                    if h[-1] == h[-2] :
                        minimum += 1
                #The maximum heat level is one more than the sum of all the previous heat levels.    
                maximum = sum(h) + 1
                #Add new heats.   
                for j in range(minimum, maximum + 1) :
                    new_heats.append(h+[j])
            #Keep adding to the set.
            heats = addOnHeats(N, new_heats, p+1)
        
        #Last level to be added.
        else :
            new_heats = []
            for h in heats :
                
                #The sum of all heat levels thus far must be at least half.
                total = sum(h)
                if total >= mF(n/2) :
                    #Add the remaining.  It could be out of order.  It could be a repeat.
                    h = tuple(sorted(h + [n-total]))
                    new_heats.append(h)
            heats = list(set(new_heats))
        return(heats)
    
    #The minimum number of heat levels is the floor of log2 n + 1.
    N = mF(mL(n, 2))+1
    #All sets of N must start with 1.
    heats = [[1]]
    #Start recursion.
    heats = addOnHeats(N, heats, 1)
    
    return(N, sorted(heats))
 
In [3]:
len(getAllHeats(10)[1])
Out[3]:
3
In [4]:
len(getAllHeats(100)[1])
Out[4]:
114
In [5]:
def plotHelper() :
    
    sns.set()

    #Plot.    
    fig = plt.figure(figsize = (12, 6))
    ax = fig.add_subplot(xlim = (1, 256))

    #Title.
    ax.set_title("How Many Sets?", fontsize = 24)

    #x-axis.
    ax.set_xlabel("Maximum Heat Level", fontsize = 18)
    ax.set_xticks([2**x for x in range(2, 9)])

    #y-axis.
    ax.set_ylabel("Possible Sets to Generate", fontsize = 18)
    ax.set_yscale("log")
#    ax.set_yticks([2**(2*y) for y in range(8)])

    ax.tick_params(axis = 'both', labelsize = 16)

    #Data
    n = list(range(1, 256))
    heats = []
    N = []

    for i in n :
        data = getAllHeats(i)
        heats.append(len(data[1]))
        N.append(data[0])

    scatter = ax.scatter(x = n, 
                         y = heats,
                         c = N,
                         cmap = 'viridis')
    h, l = scatter.legend_elements()
    l = ['1', '2', '3', '4', '5', '6', '7', '8']
    legend = ax.legend(h, l,
                       title = "Size of Set",
                       title_fontsize = 18,
                       fontsize = '16',
                       loc = 'upper left',
                       ncol = 2)
    ax.add_artist(legend);

    fig.savefig('2025.11.28EC.png', bbox_inches = "tight");
In [6]:
plotHelper()
In [7]:
print(len(getAllHeats(256)[1]), len(getAllHeats(257)[1]))
462664 465297
In [8]:
getAllHeats(10)[1]
Out[8]:
[(1, 1, 3, 5), (1, 2, 2, 5), (1, 2, 3, 4)]
In [9]:
getAllHeats(100)[1]
Out[9]:
[(1, 2, 3, 6, 13, 25, 50),
 (1, 2, 3, 6, 13, 26, 49),
 (1, 2, 3, 7, 12, 25, 50),
 (1, 2, 3, 7, 12, 26, 49),
 (1, 2, 3, 7, 13, 24, 50),
 (1, 2, 3, 7, 13, 25, 49),
 (1, 2, 3, 7, 13, 26, 48),
 (1, 2, 3, 7, 13, 27, 47),
 (1, 2, 3, 7, 14, 23, 50),
 (1, 2, 3, 7, 14, 24, 49),
 (1, 2, 3, 7, 14, 25, 48),
 (1, 2, 3, 7, 14, 26, 47),
 (1, 2, 3, 7, 14, 27, 46),
 (1, 2, 3, 7, 14, 28, 45),
 (1, 2, 4, 5, 13, 25, 50),
 (1, 2, 4, 5, 13, 26, 49),
 (1, 2, 4, 6, 12, 25, 50),
 (1, 2, 4, 6, 12, 26, 49),
 (1, 2, 4, 6, 13, 24, 50),
 (1, 2, 4, 6, 13, 25, 49),
 (1, 2, 4, 6, 13, 26, 48),
 (1, 2, 4, 6, 13, 27, 47),
 (1, 2, 4, 6, 14, 23, 50),
 (1, 2, 4, 6, 14, 24, 49),
 (1, 2, 4, 6, 14, 25, 48),
 (1, 2, 4, 6, 14, 26, 47),
 (1, 2, 4, 6, 14, 27, 46),
 (1, 2, 4, 6, 14, 28, 45),
 (1, 2, 4, 7, 11, 25, 50),
 (1, 2, 4, 7, 11, 26, 49),
 (1, 2, 4, 7, 12, 24, 50),
 (1, 2, 4, 7, 12, 25, 49),
 (1, 2, 4, 7, 12, 26, 48),
 (1, 2, 4, 7, 12, 27, 47),
 (1, 2, 4, 7, 13, 23, 50),
 (1, 2, 4, 7, 13, 24, 49),
 (1, 2, 4, 7, 13, 25, 48),
 (1, 2, 4, 7, 13, 26, 47),
 (1, 2, 4, 7, 13, 27, 46),
 (1, 2, 4, 7, 13, 28, 45),
 (1, 2, 4, 7, 14, 22, 50),
 (1, 2, 4, 7, 14, 23, 49),
 (1, 2, 4, 7, 14, 24, 48),
 (1, 2, 4, 7, 14, 25, 47),
 (1, 2, 4, 7, 14, 26, 46),
 (1, 2, 4, 7, 14, 27, 45),
 (1, 2, 4, 7, 14, 28, 44),
 (1, 2, 4, 7, 14, 29, 43),
 (1, 2, 4, 7, 15, 21, 50),
 (1, 2, 4, 7, 15, 22, 49),
 (1, 2, 4, 7, 15, 23, 48),
 (1, 2, 4, 7, 15, 24, 47),
 (1, 2, 4, 7, 15, 25, 46),
 (1, 2, 4, 7, 15, 26, 45),
 (1, 2, 4, 7, 15, 27, 44),
 (1, 2, 4, 7, 15, 28, 43),
 (1, 2, 4, 7, 15, 29, 42),
 (1, 2, 4, 7, 15, 30, 41),
 (1, 2, 4, 8, 10, 25, 50),
 (1, 2, 4, 8, 10, 26, 49),
 (1, 2, 4, 8, 11, 24, 50),
 (1, 2, 4, 8, 11, 25, 49),
 (1, 2, 4, 8, 11, 26, 48),
 (1, 2, 4, 8, 11, 27, 47),
 (1, 2, 4, 8, 12, 23, 50),
 (1, 2, 4, 8, 12, 24, 49),
 (1, 2, 4, 8, 12, 25, 48),
 (1, 2, 4, 8, 12, 26, 47),
 (1, 2, 4, 8, 12, 27, 46),
 (1, 2, 4, 8, 12, 28, 45),
 (1, 2, 4, 8, 13, 22, 50),
 (1, 2, 4, 8, 13, 23, 49),
 (1, 2, 4, 8, 13, 24, 48),
 (1, 2, 4, 8, 13, 25, 47),
 (1, 2, 4, 8, 13, 26, 46),
 (1, 2, 4, 8, 13, 27, 45),
 (1, 2, 4, 8, 13, 28, 44),
 (1, 2, 4, 8, 13, 29, 43),
 (1, 2, 4, 8, 14, 21, 50),
 (1, 2, 4, 8, 14, 22, 49),
 (1, 2, 4, 8, 14, 23, 48),
 (1, 2, 4, 8, 14, 24, 47),
 (1, 2, 4, 8, 14, 25, 46),
 (1, 2, 4, 8, 14, 26, 45),
 (1, 2, 4, 8, 14, 27, 44),
 (1, 2, 4, 8, 14, 28, 43),
 (1, 2, 4, 8, 14, 29, 42),
 (1, 2, 4, 8, 14, 30, 41),
 (1, 2, 4, 8, 15, 20, 50),
 (1, 2, 4, 8, 15, 21, 49),
 (1, 2, 4, 8, 15, 22, 48),
 (1, 2, 4, 8, 15, 23, 47),
 (1, 2, 4, 8, 15, 24, 46),
 (1, 2, 4, 8, 15, 25, 45),
 (1, 2, 4, 8, 15, 26, 44),
 (1, 2, 4, 8, 15, 27, 43),
 (1, 2, 4, 8, 15, 28, 42),
 (1, 2, 4, 8, 15, 29, 41),
 (1, 2, 4, 8, 15, 30, 40),
 (1, 2, 4, 8, 15, 31, 39),
 (1, 2, 4, 8, 16, 19, 50),
 (1, 2, 4, 8, 16, 20, 49),
 (1, 2, 4, 8, 16, 21, 48),
 (1, 2, 4, 8, 16, 22, 47),
 (1, 2, 4, 8, 16, 23, 46),
 (1, 2, 4, 8, 16, 24, 45),
 (1, 2, 4, 8, 16, 25, 44),
 (1, 2, 4, 8, 16, 26, 43),
 (1, 2, 4, 8, 16, 27, 42),
 (1, 2, 4, 8, 16, 28, 41),
 (1, 2, 4, 8, 16, 29, 40),
 (1, 2, 4, 8, 16, 30, 39),
 (1, 2, 4, 8, 16, 31, 38),
 (1, 2, 4, 8, 16, 32, 37)]

Rohan Lewis¶

2025.12.01¶