I have a list of lists of integers that are each sorted numerically. Here is a sample of it: {{2, 8, 9}, {3, 7, 9}, {4, 6, 9}, ...}
. I wish to only pick out members which meet the following criteria:
- No two elements within it are consecutive:
ContainsNone[Union@Differences[#], {1}] &
- The length of the list is itself a member of the list:
ContainsAny[#, {Length@#}] &]
Each test independently works fine:
In=Select[mylist, ContainsNone[Union@Differences[#], {1}] &]
Out={{3, 7, 9}, {4, 6, 9}, {1, 3, 6, 9}, {1, 4, 6, 8}}
In=Select[mylist, ContainsAny[#, {Length@#}] &]
Out={{3, 7, 9}, {1, 4, 5, 9}, {1, 4, 6, 8}, {2, 4, 5, 8}, {2, 4, 6, 7}, {3, 4, 5, 7}, {1, 2, 3, 5, 8}, {1, 2, 4, 5, 7}, {1, 3, 4, 5, 6}}
However when I attempt to use an And[]
function with Select[]
to only pick out lists that meet both criteria I am presented with an empty result when clearly at least {3,7,9}
meets both criteria:
In=Select[mylist,And[ContainsNone[Union@Differences[#], {1}] &,ContainsAny[#, {Length@#}] &]]
Out={}
Is it that And[]
is not working as I intend it inside this Select[]
function? Surely if Select[]
passes each member one by one, the And[]
will return True when it gets to {3,7,9}
, no? Or is it some other reason? I know I can just output each and do an Intersection[]
but I just want to figure out how to use Select to do what I intend.
myList // Select[And[pred1, pred2, ...] /* Through]
. $\endgroup$