| Author |
Comment/Response |
yehuda ben-shimol
|
09/25/11 07:22am
I'm not sure if you want ALL elements with first value greater than the min to be selected or not. The verbal explanation votes for all of them, but the "desired" results votes only for the maximum, so I will give you both solutions (which are practically the same)
perlalist = {{{5, 1, "a"}, {6, 2, "b"}, {9, 3, "c"}}, {{10, 1,
"a"}, {15, 2, "b"}, {10, 3, "c"}, {10, 4, "d"}}, {{100, 1,
"d"}, {200, 2, "g"}, {300, 4, "t"}}};
fAll[x_, l_List] := Module[{min},
min = Min[First /@ l];
Select[l, First[#] - min >= x &]];
Flatten[fAll[5, #] & /@ perlalist, 1]
You can also use Pattern Matching
fAllPM[x_, l_List] := Module[{min},
min = Min[First /@ l];
Cases[l, {left_, mid_, right_} /; left - min >= x]];
Flatten[fAllPM[5, #] & /@ perlalist, 1]
As for the function that returns the "DESIRED" result
fMax[x_, l_List] := Module[{min, max},
min = Min[First /@ l];
max = Max[First /@ l];
Cases[l, {max, mid_, right_} /; max - min >= x]];
Flatten[fMax[5, #] & /@ perlalist, 1]
yehuda
URL: , |
|