Input:
Select[Range[10], 2 <= # <= 5 || 8 <= # <= 10 &]
Output:
{2, 3, 4, 5, 8, 9, 10}
In case I have lots of conditions I want to have them defined separately like this:
Input:
cond = {{2, 5}, {8, 10}};
Or @@ (#[[1]] <= q <= #[[2]] & /@ cond)
Output:
2 <= q <= 5 || 8 <= q <= 10
How to combine my first input with my second input to have all the code in my formula?
Between[]
:Select[Range[50], Between[{{2, 5}, {11, 19}, {26, 33}, {44, 49}}]]
$\endgroup$With[{sel = ReleaseHold[Hold[Function][Apply[Or, # <= Hold[Slot][1] <= #2 & @@@ {{2, 5}, {11, 19}, {26, 33}, {44, 49}}]]]}, Select[Range[50], sel]]
suit your needs? $\endgroup$cond = {{2, 5}, {8, 10}}; test[x_] = Or @@ (#[[1]] <= x <= #[[2]] & /@ cond); Select[Range[10], test]
$\endgroup$