How to build a function to return the nearest number from a set of -unstored numbers?

I need to build a function that given a number it either returns the number within the set (not stored) or returns an approximation of the possible highest and lowest number within the set for the given input.

For example the following is the set of numbers. This set is not stored so the function should be created when this set is created.

Set = {1, 2, 10, 15, 20, 31, 50, 90, 101, 200}

If input = 20. Output should be 20

If input = 25. Output should be 20 (lowest) and 31 (highest).

Is this possible?

• Are you asking for an algorithm to perform this computation? Oct 31 '19 at 7:24
• What do you mean by "possible" ? You could just define the following: Let $\mathbb{R}^n$ be the set of sets of real numbers of size $n$. Then, when set $A\in \mathbb{R}^n$, $$f_A: \mathbb{R} \to \mathbb{R}^n: f_A(x) = \left\{ \begin{split} (x), & ~\text{if } x \in A \\ (\max{A}, \min{A}),& ~\text{otherwise} \end{split} \right.$$ Oct 31 '19 at 7:26
• What do you mean by not stored? Oct 31 '19 at 7:30
• @angryavian - Yes. An algorithm or a function. Oct 31 '19 at 7:34
• I have a feeling that this is more of a programming question than mathematics question. From a mathematical point of view, it's not difficult to just define this kind of function. Oct 31 '19 at 7:36