Party time! All of your guests are sitting around a round table, but they have very particular seating requirements. Let's write a program to organize them automatically!
Guests are represented by letters: Female guests are uppercase, males are lowercase. Couples have the same letter, one lower and one upper, like
gG, who just had their golden marriage (congrats!).
- Neither place a male between two other males nor a female between two other females.
- Couples must sit next to each other.
- Alphabetically adjacent letters of the same sex are rivals! Never place two rivals next to each other (like
BA) or a rival next to the partner of an attendant partner (like
xaBczis fine, because none of them have jealous partners at the party). Answering a comment:
Zare not adjacent in any alphabet I'm aware of. (-;
You may take input as either a string or a list of letters
[a-zA-Z] *(or, only if your language of choice has no characters, integers from 1 to 52 representing them, males are even, females are odd :-), which will always be unique (i.e. no duplicates). Remember: this is a round table, so ensure that your answer takes wrapping into account.
Your output has to be at least one of all possible table arrangements for the input. Where the cut is doesn't matter. If no valid arrangements exist for the input, give an output of your choice which is obviously no sitting arrangement, from an ugly program crash over empty output to some polite message (sorry, no extra score for that).
A --> A (boring party, but valid) BbCc --> <none> gdefEDH --> HfdDgeE OMG --> <none> hiJk --> <none> hMJkK --> hJMkK NoP --> NoP rt --> rt qQXZxyz --> <none> BIGbang --> bIgGanB
(P.S.: In case you miss same-sex couples, non-binaries, polycules, and such – I like those at my personal party, but not in this challenge, to keep it simple.)