There are several related questions, but I'm looking for a solution specific to my case. There is an array (usually) of 14 integers, each of which is in the range from 1 to 34. How can I quickly say if every int in a particular static list appears at least once in this array?
For reference, I am currently using this code, which was written as close to the specification as possible, so it can be greatly improved:
if (array.Count < 13) {
return;
}
var required = new int[] {
0*9 + 1,
0*9 + 9,
1*9 + 1,
1*9 + 9,
2*9 + 1,
2*9 + 9,
3*9 + 1,
3*9 + 2,
3*9 + 3,
3*9 + 4,
3*9 + 5,
3*9 + 6,
3*9 + 7,
};
IsThirteenOrphans = !required.Except (array).Any ();
The required list is not dynamic, i.e. at run time it will always match. Using Linq is optional, the main aspect is performance.
Edit:
- The input array is not sorted.
- Input values may appear several times.
- 14 , .. 1 .
- 1 .
- , , .
- , .
: .