# Sort my Cups︎︎︎︎︎︎︎︎︎︎ [closed]

I have a set of colored plastic cups. They come in four colors: green, yellow, pink, and blue. When I put them on my shelf, I like to stack them in a certain pattern. Your job is, given a list of any number of four distinct values (to represent the four cup colors), output a visual representation of how I would stack them.

## Rules

• The cups must be sorted into either two or three stacks.
• Green and yellow must always be paired with either pink or blue. Which one is paired with which does not matter but must be consistent.
• If there are an even number of pairs, they must be sorted into two stacks, with each stack having the same number of pair types (unless there are only two pairs, in which case they can be put in any order)
• The pink and blue cups in a pair must be above the green and yellow ones.
• Pairs with yellow cups must be above pairs with green cups.
• Any remaining cups must be evenly distributed amongst the bottoms of the stacks.
• If there are an even number of pairs and an even number of leftovers, use two stacks.
• If there are an odd number of ether pairs of leftovers, use three stacks. The extra cups and leftovers must go in the middle stack.
• Extra cups must be sorted in this order: Yellow above green above blue above pink.

## Output

Output must be a representation of the cup layout. Each color must be represented as a consistent one-character value, arranged into columns. A space must be used for empty slots. See below for examples.

## Examples

Using GYPB for green, yellow, pink and blue respectively

Input: GGYYPPBB
Output:
BB
YY
PP
GG

Input: GYPB
Output:
PB
GY
or
BP
YG

Input: PPGGBBYYY
Output:
B B
Y Y
P P
GYG

Input: PGPBYBPG
Output:
B
Y
PBP
GPG

• Could you add the following test cases: GGGYYYPB, GY? (I might be missing something, but I don't see how these could conform to the given rules) Jun 7, 2022 at 15:35
• Why do B and Y stand on their own in the last test case? Could you not do something like BB, PP, GG, PY? Jun 8, 2022 at 15:56
• @Ajax1234 Wouldn't that break the rule that the pink and blue cups in a pair must be above the green and yellow ones? Jun 9, 2022 at 22:33
• @Steffan Perhaps, but in the second and third examples, GY and GYG exist, when "Pairs with yellow cups must be above pairs with green cups." In fact, why could the second example not be BB, YYY, PP, GG? Jun 9, 2022 at 22:52