Sharedworking.sagewsOpen in CoCalc
Working code for DoP
#The algorithm below prints all partitions that can be obtained from a given "seed" list of partitions by adding 2 boxes at a time

# We print partitions in the French style
Partitions.options(diagram_str='♬', convention="french")
def main():

# This is the number of iterations of the procedure we run
max_run = 10
# t is a dummy variable that keeps track of the current iteration of the procedure
t = 1
# seed is our "seed" list of partitions, from which we build all the others
seed = [Partition([2]),Partition([1,1]),Partition([2,2])]
difficulty = 1

while t <= max_run:
new_seed = []
print(t)
print('')
print(seed)
print('')
# For every partition in the seed, we print its diagram, find all the new partitions that can be produced from it, and add these new partitions to the next seed
for part in seed:
print(part.ferrers_diagram())
print('')
# At the end of this procedure, we take the new seed and feed it into the next iteration
seed = new_seed
t += 1

# doubles checks to see whether a given pair of corners can be added
def doubles(x1, x2, y1, y2, x_list, y_list, dist):
num_corners = len(x_list)
double = True
for i in range(num_corners):
# The distance from a corner to itself is always 0, so we need to exclude this case
if x_list[i] != x1 and x_list[i] != x2:
# otherwise, compute the distance
dist1 = distance(x1, x_list[i], y1, y_list[i])
# We choose a large prime to stand in for the distance from a corner to itself
else:
dist1 = 641
# We check to see if the distance is divisible by the distance between the 2 corners we wish to add
if dist1 % dist == 0:
double = False
return double

# corners produces two lists corresponding to the outside corners of a partition, one consisting of the x coordinates, the other consisting of the y coordinates
def corners(partition):
x_tup, y_tup = zip(*partition.outside_corners())
x_list = list(x_tup)
y_list = list(y_tup)
return x_list, y_list

# incorners produces two lists corresponding to the inside corners of a partition, one consisting of the x coordinates, the other consisting of the y coordinates
def incorners(partition):
inx_tup, iny_tup = zip(*partition.inside_corners())
inx_list = list(inx_tup)
iny_list = list(iny_tup)
return inx_list, iny_list

# distance computes the lattice distance between two points in the xy plane
def distance(x_1, x_2, y_1, y_2):
distance = int(abs(x_1 - x_2) + abs(y_1 - y_2))
return distance

# find_part produces all partitions that can be produced from a given partition by adding valid pairs of boxes
def find_part(partition):
list_part = []
# We first identify all of the outside and inside corners
x_list, y_list = corners(partition)
inx_list, iny_list = incorners(partition)
num_corners = len(x_list)
for i in range(num_corners):
for j in range(num_corners):
if j > i:
x1 = int(x_list[i])
y1 = int(y_list[i])
x2 = int(x_list[j])
y2 = int(y_list[j])

# For every pair of corners, we compute the distance
dist = distance(x1, x2, y1, y2)
# doub will be True if the partition obtained by adding the given pair is an upward displacement of the original partition
doub = doubles(x1, x2, y1, y2, x_list, y_list, dist)
# indoub will be True if the original partition is a downward displacement of the new partition
indoub = doubles(x1, x2, y1, y2, inx_list, iny_list, dist)

# If both doub and indoub are True, we may add the pair of corners
if doub == True and indoub == True: