Question:
Given a number, I need to find out which of the following rows/lists it exists in. But I don't want generate them, given that there are a lot of lists and they grow bigger over time.
We are given the following patterns.
$a = \textbf{0}, 4, 5, 9, 10, 14, 15, 19, 20, ..., n \quad\textbf{[+4, +1]}$
$b = \textbf{1}, 5, 8, 12, 15, 19, 22, 26, 29, ..., n\quad\textbf{[+4, +3]}$
$c = \textbf{1}, 9, 12, 20, 23, 31, 34, 42, 45, ..., n\quad\textbf{[+8, +3]}$
$d = \textbf{2}, 10, 15, 23, 28, 36, 41, 49, 54, ..., n\quad\textbf{[+8, +5]}$
$e = \textbf{2}, 14, 19, 31, 36, 48, 53, 65, 70, ..., n\quad\textbf{[+12, +5]}$
$f = \textbf{3}, 15, 22, 34, 41, 53, 60, 72, 79, ..., n\quad\textbf{[+12, +7]}$
$g = \textbf{3}, 19, 26, 42, 49, 65, 72, 88, 95, ..., n\quad\textbf{[+16, +7]}$
$h = \textbf{4}, 20, 29, 45, 54, 70, 79, 95, 104, ..., n\quad\textbf{[+16, +9]}$
$i =$ Etc.
Examples:
Where is 4? -> 4 is in list 1 (1,2)
Where is 5? -> 5 is in list 1 (1,3) and/or list 2 (2,2) [one answer is enough]
Only the list is of importance, the position within not so much.
When it comes to finding a given number, the amount of testing is also of crucial importance. As the whole point of this is to try and achieve the most optimal time complexity.
Since there are multiple solutions possible, you cannot just have one function. It is possible however to check if any number is part of a particular pattern. A pattern is described by three numbers. For computational simplicity, I will choose $a_{n,0}$ the first element of series $n$, the first step $t_n$, and the sum of the steps as $s_n$. A number $x$ is in series $n$ if either $(x-a_{n,0})$ or $(x-a_{n,0}-t_n)$ is divisible by $s_n$.
So now the problem simplifies to calculating $a_{n,0}$, $s_n$, and $t_n$ as functions of $n$. The first element can be written as $$a_{n,0}=\left\lfloor\frac n2\right\rfloor$$
For $t_n$ we can see a similar pattern $$t_n=4\left\lfloor\frac {n+1}2\right\rfloor$$ Finally, the second step is $2a_{n,0}+1$, so $$s_n=4\left\lfloor\frac {n+1}2\right\rfloor+2\left\lfloor\frac n2\right\rfloor+1$$