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.
- 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 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.
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