This challenge is adapted from the British Informatics Olympiad.
Dice game
Two players are playing a dice game where they each roll a pair of dice, and the highest sum wins. The pairs of dice have the same number of sides, but do not have to have the same values on each side. Therefore, the game is fair if for both pairs of dice all possible sums can be made with equal probability.
For example, if Player 1 has the following dice:
{1,2,3,4,5,6} {1,2,3,4,5,6}
Then they can produce the following sums:
1 2 3 4 5 6
+------------------
1| 2 3 4 5 6 7
2| 3 4 5 6 7 8
3| 4 5 6 7 8 9
4| 5 6 7 8 9 10
5| 6 7 8 9 10 11
6| 7 8 9 10 11 12
If Player 2 has:
{1,2,2,3,3,4} {1,3,4,5,6,8}
They can produce:
1 2 2 3 3 4
+------------------
1| 2 3 3 4 4 5
3| 4 5 5 6 6 7
4| 5 6 6 7 7 8
5| 6 7 7 8 8 9
6| 7 8 8 9 9 10
8| 9 10 10 11 11 12
This game is fair as the minimum for both is 2, the maximum is 12, and each sum occurs the same number of times, e.g 7 can be made 6 ways with each pair.
Challenge
Write a program/function that takes two dice as input, and optionally an integer representing the number of sides each dice contain, and prints/returns a different pair of dice that could be used to play a fair game with the two input dice, or any falsey value if there is no solution different from the input.
Specifications
The number of sides on both dice must be the same, and equal to the number of sides on the input pair of dice. This number will always be an integer greater than or equal to 1.
The two dice returned can be the same, but the pair must not be the same as the input pair.
Different order pairs are not different; {1,2,3} {4,5,6} is the same as {4,5,6} {1,2,3}.
Your program does not need to produce a result quickly, as long as it will eventually produce correct output.
The values on the input pair of dice dice will always be integers between 1 and 9 inclusive, but the values returned can be any integer ≥1.
If there is more than one possible solution, only one needs to be returned.
Input/Output can be in any reasonable format.
Test Cases
6
1 2 2 3 3 4
8 6 5 4 3 1
1 2 3 4 5 6
1 2 3 4 5 6
4
1 1 1 1
1 4 5 8
1 1 4 4
1 1 5 5
3
1 3 5
2 4 6
False
8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
Any of the following:
1 2 2 3 3 4 4 5 | 1 2 2 3 5 6 6 7 | 1 2 3 3 4 4 5 6
1 3 5 5 7 7 9 11 | 1 3 3 5 5 7 7 9 | 1 2 5 5 6 6 9 10
9
? I only see ruling about the sides being>=1
, but is there a max? If it can be higher than 9, would you mind adding a test case for it? \$\endgroup\$