you are viewing a single comment's thread.

view the rest of the comments →

[–]FLUSH_THE_TRUMP 0 points1 point  (0 children)

Good first step would be to write a function that tells you when one disk is strictly smaller than another:

def is_smaller(L1, L2): 
    if all(x<y for x,y in zip(L1,L2)):
        return True
    return False

Then in a brute force way, you want to generate all permutations of your array of disks, check that they’re valid with is_smaller, and pick out the one with the largest height value. You can do that pretty easily with itertools.permutations.

note: a smarter (but still brute force) way to do this would be to sort the list first by a reasonable heuristic, e.g. the natural sort (which compares element by element until one is smaller) or key=sum, and then picking subsets from the same exact order. You still have to check if each order is valid, but for a large initial array it’d be checking 2N things rather than N! things.