Input:
Input is a randomized array of nuts (in your language), the possible nuts follow. Your program must have a way of representing each kind of nut, such as an integer code. Program must be able to handle any size array of any configuration of nuts.
Possible Nuts:
Kola nut
Macadamia
Mamoncillo
Maya nut
Mongongo
Oak acorns
Ogbono nut
Paradise nut
Pili nut
Pistachio
Walnut
Output:
Output must be the array sorted in such a fashion that there are no adjacent nuts of the same kind. If this is impossible, the output should be an empty array.
Example Input (simplified):
["walnut", "walnut", "pistachio"]
Example Output:
["walnut", "pistachio", "walnut"]
Solutions may not simply shuffle the array until it becomes unique by chance. The sort employed must be a deterministic one
perl6 -e 'my @a="aaaaabbbbccccdddee".comb;my @b = @a.pick(*) while @b.squish !== @a;say [~] @b'
baedcbdacdecbabaca
(3,3,2) may cause them to fail also. \$\endgroup\$