Given a list of positive integers as input you are to determine if there is a way to pair up the elements such that:
- All but one element is in a pair
- No element is in more than one pair
- Every pair is of equal elements
- No two pairs have elements separated by the same distance in the original list
For example if the input is:
[2,2,1,2,3,3,1]
Then we can choose the following pairs:
[2,2,1,2,3,3,1] <- Input
[2, 2] % Separated by 2
[1, 1] % Separated by 4
[3,3] % Separated by 1
The first 2
is the element which is not in a pair.
Very importantly, when you take the list of code points of your program it must satisfy the property. Answers which do not are invalid.
This is code-golf the goal is to minimize the size of your source code as measured in bytes while satisfying the constraints.
To decide, your program should output one of two fixed values. The first if the solution there is a pairing of the input list as described and the second of the two values if there is not.
Test cases
Pairing possible
[1]
[1,1,1]
[1,1,1,1,1]
[2,2,1,1,1]
[2,2,1,2,1]
[2,2,1,2,3,3,1]
[2,2,2,1,2,3,3]
Pairing not possible
[]
[1,1]
[1,2,3]
[1,1,1,1]
[2,2,1,2,3]
[2,2,1,3,3]
[1,1,1,1,1,1]
[2,2,2,2,1,3,3]
ab
thenab#ab
is not a valid program, it doesn't pass the restriction. \$\endgroup\$