Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting with Cases

Please Consider :

Subsets[Flatten[ParallelTable[{i, j}, {i, 1, 96}, {j, 1, 4}], 1], {4}]

I need to select all the Sublist such that the the i value is never the same within each sublist of 4

{{3,1},{4,1},{5,1},{6,1}} should be accepted while {{1,1},{1,2},{2,3},{6,1}} should be rejected. The Value 1 for i being repeated 2 times.

I know I could do this with Cases, but don`t understand the Syntax of it, and find the help on Cases rather empty compared to its potential applications.

like image 606
500 Avatar asked May 01 '26 06:05

500


1 Answers

Assuming your data is in the variable data, the following should do it:

Select[data, Length@Union[#[[All, 1]]] === 4 &]

This takes the "i"-value (i.e. first element), and checks that the 4 values are all different (i.e. if we remove the duplicates we still have 4 of them)

like image 182
Szabolcs Avatar answered May 02 '26 20:05

Szabolcs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!