Challenge
Given a list of positive integers, find if there exists a permutation where taking up to one bit from each of the integers, a binary number consisting of all 1
s can be created.
The number of bits in the resulting binary number is equal to the highest MSB in the list of integers.
Output
Your code must output or return a truthy/falsey value indicating if such a permutation exists.
Examples
Truthy:
With the list [4, 5, 2]
, and its binary representation [100, 101, 10]
, we can use the third, first, and second bits, respectively, to create 111
:
4 -> 100 -> 100 -> 1
5 -> 101 -> 101 -> 1
2 -> 010 -> 010 -> 1
Result 111
With the list [3, 3, 3]
, all of the numbers have both first and second bits set as 1
, so we can take our pick with a number to spare:
3 -> 11 -> 11 -> 1
3 -> 11 -> 11 -> 1
3 -> 11 -> 11 ->
Result 11
Falsey:
With the list [4, 6, 2]
, none of the numbers have the first bit set as 1
, so the binary number cannot be created:
4 -> 100
6 -> 110
2 -> 010
With the list [1, 7, 1]
, only one of the numbers has the second and third bits set as 1
, and the number cannot be created:
1 -> 001
7 -> 111
1 -> 001
Obviously, if the maximum number of set bits exceeds the number of integers, the result number can never be created.
Test cases
Truthy:
[1]
[1, 2]
[3, 3]
[3, 3, 3]
[4, 5, 2]
[1, 1, 1, 1]
[15, 15, 15, 15]
[52, 114, 61, 19, 73, 54, 83, 29]
[231, 92, 39, 210, 187, 101, 78, 39]
Falsey:
[2]
[2, 2]
[4, 6, 2]
[1, 7, 1]
[15, 15, 15]
[1, 15, 3, 1]
[13, 83, 86, 29, 8, 87, 26, 21]
[154, 19, 141, 28, 27, 6, 18, 137]
Rules
Standard loopholes are forbidden. As this is code-golf, shortest entry wins!