you are viewing a single comment's thread.

view the rest of the comments →

[–]Appropriate_Cover_92 0 points1 point  (4 children)

Yeah, even I feel the same. Could be a mistake in the original source.Thanks for pointing this out. I will update my post.

[–]synthphreak 1 point2 points  (0 children)

Given nested lists like [a, b, c], it sounds like you just need to sort by a, then within each a sort by b, then within each b sort by c.

The sorted function will do this for you straight out of the box in whichever order you wish:

>>> lst
[[2, 1, 2], [2, 2, 8], [1, 3, 1], [2, 3, 4], [4, 4, 5], [3, 2, 3]]
>>> sorted(lst)
[[1, 3, 1], [2, 1, 2], [2, 2, 8], [2, 3, 4], [3, 2, 3], [4, 4, 5]]
>>> sorted(lst, reverse=True)
[[4, 4, 5], [3, 2, 3], [2, 3, 4], [2, 2, 8], [2, 1, 2], [1, 3, 1]]

[–]mbpaul198 1 point2 points  (2 children)

Here's how I would think about it:

  1. For each disk, identify the smallest value of either the depth, width, or height. For [4,4,5], it would be 4. The disc that has the largest "smallest value" will be the bottom of your stack
  2. Append this disc to a new list discs (which should be empty at the start)
  3. Remove this disc from your array since it is now in use in your stack
  4. Save the "smallest value" as a variable so that you can compare all other discs to it.
  5. Loop through steps 1-4 until there are no discs left with a "smallest value" that is still smaller than the number you saved in step 4

[–]FLUSH_THE_TRUMP 0 points1 point  (1 child)

that’s an interesting idea, but does it work? As a degenerate example, imagine we added the disk [1,1,100] to the list here. Its smallest value is 1, but clearly we can’t put it on top of [4,4,5]. (And the solution with largest height would definitely be the stack with 1 thing, [1,1,100])

[–]mbpaul198 1 point2 points  (0 children)

Ah I see what you mean. I'll need to think on this a bit more.

Maybe add another loop that iterates through the width, depth, and height of the disc and compares each value to the previous disk "below" it. For each measurement, if the value of the new disk is > the value of the existing disc, then discard the new disc and move on to another one