The approach you use would depend on how many particles your talking about. For four particles, you could simply have the expression compare all four particle positions each frame. For a variable number of particles, you would need to run a nested for-loop to cycle as in the following code. Note that you need to do a little vector math here, and that the "getParticleAttr" call returns a float array, not a vector. I did this somehow at work without the float array I think, but I don't have that script here. I'll check that tomorrow morning. Also, I did not simplify this code on purpose and I didn't test it, but something close should work - I've done it before.
int $i, $j;
float $minDistance = ;//your minimum cutoff value here
float $maxDistance = ;//your maximum cutoff value here
int $sizeParticles = getAttr particleShape1.count;
for ($i=0;$i{
float $partPos1[] = getParticleAttr -at position
particleShape1.pt[$i];
for ($j=0;$j {
float $partPos2[] = getParticleAttr -at position
particleShape1.pt[$j];
float $temp1 = $partPos1[0];
float $temp2 = $partPos1[1];
float $temp3 = $partPos1[2];
float $temp4 = $partPos2[0];
float $temp5 = $partPos2[1];
float $temp6 = $partPos2[2];
//vector math
float $pos1 = pow($temp4-$temp1, 2);
float $pos2 = pow($temp5-$temp2, 2);
float $pos3 = pow($temp6-$temp3, 2);
float $pos4 = $pos1 + $pos2 + $pos3;
float $pos5 = sqrt($pos4);
if (($pos5 > $minDistance) && ($pos5 < $maxDistance))
//your routine here
else
continue;
}
}