This is a challenge in which two people, 1 and 2, are running for office. People deterministically vote in certain ways in the world of 1 and 2, which can allow for the candidates to figure out the results before the election.
NOTE: this is not meant to refer to any outside elections or other political events.
Two people are running for office. We'll call these people 1 and 2. Because they both want to know if they will win the election, they decide to use their knowledge of people and some code to figure out what the result will be. Due to the want to minimize government spending, the code needs to be a short as possible.
Your task: Given a string of people based on how they are voting, output who wins the election.
There are five kinds of people in the fun and exciting world of 1 and 2:
A: people who will definitely vote for 1.
B: people who will definitely vote for 2.
X: people who will vote for whoever the person to their left will vote for. If there is no person to their left, then they vote for whoever the person at their right will vote for. If it is not clear who the person to their right is voting for, then they do not vote.
Y: people will vote the opposite of the person to their left. If there is no person to their left, then they vote opposite of whoever is at their right. If it is not clear who the person to their right is voting for, then they do not vote.
N: people who do not vote.
This is evaluated from left to right.
Whoever is being "evaluated" is in lowercase, for clarity.
Input: `XXAYAN` xX Votes for whoever their friend is voting for. Their friend has not decided yet, so it is unclear, so they do not vote. Xx Person to left is voting "none" so votes "none." a Votes for 1 Ay Since person on left is voting for 1, votes for 2. a Votes for 1 n Does not vote
2 people voted for 1
1 people voted for 2
3 people did not vote
1 has the most votes, so 1 wins!
You may use other characters or values as input and output, as long as they are distinct. (For example: numbers instead of letters, different letters, lowercase letters, truthy/falsy or positive/negative (for output), etc.)
Input -> Output "AAAA" -> 1 "BBBB" -> 2 "BBAXY" -> 2 "BAXYBNXBAYXBN" -> 2 "XXAYAN" -> 1 "AAAABXXXX" -> 2 "AXNXXXXAYB" -> 1 "NANNY" -> 1 "XA" -> 1 "YAB" -> 2 "XY" -> anything (do not need to handle test cases with no victor) "AB" -> anything (do not need to handle test cases with no victor)