You can select all sublists the elements of which differ by more than 3 as follows:
Select[tt, Abs[#[[1]] - #[[2]]] > 3 &]
(*{{4, 8}}*)
or using conditional patterns:
Cases[tt, x_ /; Abs[x[[1]] - x[[2]]] > 3]
(and you can delete them by either selecting those Not
satisfying the condition, or using DeleteCases
).
You could also do
Scan[If[Abs[#[[1]] - #[[2]]] > 3, Sow[#]] &, tt] // Reap //
Last // Last
or even
MapThread[If[Abs[#1 - #2] > 3, Sow[{#1, #2}]] &, Transpose@tt]; //
Reap // Last // Last
Finally using Compile
and Internal`Bag
, as described by Andy here, you can do
cs = Compile[{{lst, _Integer, 2}},
Module[{bag = Internal`Bag[], l = Length@lst},
Do[
If[
Abs[lst[[i, 1]] - lst[[i, 2]]] > 3.,
Internal`StuffBag[
bag,
lst[[i]], 1
]
],
{i, l}
];
Partition[Internal`BagPart[bag, All], 2]],
CompilationTarget -> "C",
RuntimeOptions -> "Speed"
];
which is roughly as fast as the Pick
approach described in another answer (neither unpacks).