The question is how to determine a function which would decide if a pair of persons can communicate with each other, where communication is possible only if the distance between two individuals are less than $k$ units apart. For example:
If following are the coordinates in which the people reside on the $x$-axis:
$10$, $13$, $18$, $15$, $33$, and value of $k$ is $3$.
Then $10$ and $13$ can communicate, and $13$ and $18$ can't communicate directly but $13$ to $15$ and $15$ to $18$ is possible, hence $13$ and $18$ can communicate. But, $33$ can't communicate with any person.
How would one design a function which determines if communication is possible between a pair of persons?
If the coordinates are $a_1 < a_2 < \cdots < a_n$, then $a_i$ can communicate with $a_j\ (i < j)$ iff $$f(a_i,a_{i+1}) \cap f(a_{i+1},a_{i+2})\cap \cdots \cap f(a_{j-1},a_{j}) $$ where $f(x,y)$ is $True$ if $x$ can communicate with $y$, else $False$. So a function that does what you want, for input coordinates $x$ and $y$, is given by the formula
$$\bigcap_{m=i}^{j-1} f(a_m,a_{m+1}) $$ where $a_i = \min(x,y)$ and $a_j = \max(x,y)$.
E.g., implemented in Sage:
where
x,yare the coordinates to test,Lis the list of coordinates, andkis the distance criterion.