Here's a table of the ball colors in a format which makes the pattern a little more visible:
$$\begin{array}{|rr|rr|rr|}
\hline
\color{red}{1} & \color{red}{2} & \color{blue}{3} & \color{blue}{4} & \color{green}{5} & \color{green}{6}\\
\color{red}{7} & \color{red}{8} & \color{blue}{9} & \color{blue}{10} & ** & \color{green}{11}\\
\color{red}{12} & \color{red}{13} & \color{blue}{14} & \color{blue}{15} & \color{green}{16} & \color{green}{17}\\
\color{red}{18} & \color{red}{19} & \color{blue}{20} & ** & \color{green}{21} & \color{green}{22}\\
\color{red}{23} & \color{red}{24} & \color{blue}{25} & \color{blue}{26} & \color{green}{27} & \color{green}{28}\\
\color{red}{29} & \color{red}{30} & ** & \color{blue}{31} & \color{green}{32} & \color{green}{33}\\
\color{red}{34} & \color{red}{35} & \color{blue}{36} & \color{blue}{37} & \color{green}{38} & \color{green}{39}\\
\color{red}{40} & ** & \color{blue}{41} & \color{blue}{42} & \color{green}{43} & \color{green}{44}\\
\color{red}{45} & \color{red}{46} & \color{blue}{47} & \color{blue}{48} & \color{green}{49} & \\
\hline
\end{array}$$
The pattern is easier to express mathematically if we subtract 1 from the ball number, so that the numbers start from zero.
We can calculate the color of a number $i$ using this formula:
Let $j = i - 1$
Then
$$k = floor(((j + floor(j / 10)) \mod 6) / 2)$$
$k$ will be in ${{0, 1, 2}}$, with 0 = red, 1 = blue, 2 = green.
So subtract 1 from the ball number $i$ to get $j$. Then divide $j$ by 10, rounding down, and add that to $j$. Now find the remainder of that total, mod 6. Finally, divide that remainder by 2 (rounding down) to get the color number.
Here's a short Python script which tests that formula.
red = [1, 2, 7, 8, 12, 13, 18, 19, 23, 24, 29, 30, 34, 35, 40, 45, 46]
blue = [3, 4, 9, 10, 14, 15, 20, 25, 26, 31, 36, 37, 41, 42, 47, 48]
green = [5, 6, 11, 16, 17, 21, 22, 27, 28, 32, 33, 38, 39, 43, 44, 49]
groups = [[], [], []]
for i in range(1, 50):
j = i - 1
u = (j + j // 10) % 6 // 2
groups[u].append(i)
print(red == groups[0])
print(blue == groups[1])
print(green == groups[2])
You can run it on the SageMathCell server here. The table at the start of this answer was also created in Sage / Python using the above formula. Here's the table script.
u = (11 * j // 10) % 6 // 2– PM 2Ring Feb 11 '21 at 09:47