Imagine this sequence made of letters $\{a, b, c\}$:
$$a_1, b_1, c_1, a_2, a_2, b_2, b_2, c_2, c_2, a_3, a_3, a_3, b_3, b_3, b_3, c_3, c_3, c_3, \dots$$
and we will divide it into groups of $N$ and place them into a table with each row containing a group. We need to determine the value of $[P,Q]$ where $P$ represents row and $Q$ represents column.
For example, if we divide it into group of $4$, it will look like \begin{array}{|c|c|c|c|} \hline \mathbf{P} & \mathbf{Q} & \mathbf{R} & \mathbf{S} \\ \hline \mathrm{a}_1 & \mathrm{b}_1 & \mathrm{c}_1 & \mathrm{a}_2 \\ \hline \mathrm{a}_2 & \mathrm{b}_2 & \mathrm{b}_2 & \mathrm{c}_2 \\ \hline \mathrm{c}_2 & \mathrm{a}_3 & \mathrm{a}_3 & \mathrm{a}_3 \\ \hline \mathrm{b}_3 & \mathrm{b}_3 & \mathrm{b}_3 & \mathrm{c}_3 \\ \hline \mathrm{c}_3 & \mathrm{c}_3 & \mathrm{a}_4 & \mathrm{a}_4 \\ \hline \end{array}
Now, I need to determine the value of $m$th row and $n$th column after dividing it in group of $T$. I came up with a formula that can determine the column of $a_n$ in the table but I want to make it more effective so I can determine the exact value just by row and column number. For example, if we divide it in group of $7$, $a_3$ is $[2,3]$, $a_4$ is $[3,5]$, $a_5$ is $[5,3]$ and so on, but I couldn't go any further.
By the way, the formula for column position of $a_n$ is: $\{3n(n+1) / 2 \% T\} + 1$ where T is number of total column.
It's not a typical academic question. Rather, I made it after observing a game played by children, and was curious to find the pattern behind it. Some may find this math hilarious but hope a kind soul will help me with my curiosity, thanks in advance! Again, thanks!
First of all, let's split the problem into two parts. (1) What is the correspondence between position in the sequence and letter? (2) What is the correspondence between position in your rectangular table and position in the sequence?
Of these, #1 is the trickier one. Let's number our sequence starting at 0; then the position of the first $a_1$ is 0, the position of the first $a_2$ is 3 more than that, the position of the first $a_3$ is 6 more than that, and so on. So the position of the first $a_k$ is 3 times ($0+1+\cdots+k-1$), which equals $\frac{3k(k-1)}2$.
But you already have essentially that formula, and I think you want the reverse. So, what's in position $n$? The answer will be "the first $a_k$" exactly when $n=\frac{3k(k-1)}2$, which gives us a quadratic equation for $k$: $3k^2-3k-2n=0$. The standard formula for quadratic equations tells us that this is true when $k=\frac{3\pm\sqrt{9+24n}}{6}$. This gives two solutions, but of course we have to take the $+$ sign to get a positive value of $k$. Let's double-check this: the first $a_3$ is at position 9 (remember that we're counting from 0), and putting in $n=9$ gives $k=\frac{3+\sqrt{9+216}}{6}=\frac{3+\sqrt{225}}6=\frac{3+15}6=3$. Good.
But what if $n$ isn't the position of the first $a_k$ for any $k$? Well, suppose it's the position of the $j$th $L_k$ where $L$ is any of $a,b,c$; then $n$ will be somewhere between the position of the first $a_k$ (inclusive) and the position of the first $a_{k+1}$ (exclusive). And so the formula above will give us a number between $k$ (inclusive) and $k+1$ (exclusive), so taking its integer part will give us the value of $k$.
Once we have that, we can go in the other direction to get the position of the first $a_k$, and subtract that from $n$ to find how far past the first $a_k$ we are. The answer will be somewhere from 0 (for the first $a_k$) to $3k-1$ (for the last $c_k$. There are $k$ of each letter, so if we divide by $c$ then the (integer part of the) quotient will tell us which letter and the the remainder will tell us which instance of that letter.
So let's put this together. To find the letter in position $n$ (counting from 0):
We aren't quite done, because you have your letters arranged in a table with rows of length $T$. So if we want the letter in row $R$ and column $C$, where again I'm going to number them from 0:
Let's do a concrete example. What's in the last cell of the table in your image? That's the fifth row and the fourth column, so counting from 0 we have $R=4,C=3$. And the table rows are of length 4 so $T=4$. So: