We know that the rationals are countable since we can list them via zig-zagging:
$$\begin{matrix} \frac{1}{1} && \frac{1}{2} &\color{red}\to &\frac{1}{3} &&\frac{1}{4} & \color{red}\to & \frac{1}{5}\\ \color{red}\downarrow & \color{red}\nearrow && \color{red}\swarrow && \color{red}\nearrow &&\color{red}\swarrow\\ \frac{2}{1} && \frac{2}{2} && \frac{2}{3} \\ & \color{red}\swarrow && \color{red}\nearrow\\ \frac{3}{1}&&\frac{3}{2}&&& \ddots\\ \color{red}\downarrow&\color{red}\nearrow\\ \frac{4}{1} \end{matrix}$$
Now suppose we have a function $f: \mathbb N^2 \to A$ for some set $A$, where we list the outputs of the function in the same way: $$\begin{matrix} f(1,1) && f(1,2) && f(1,3) && f(1,4) && f(1,5)\\ ~\\ f(2,1) && f(2,2) && f(2,3) \\ ~\\ f(3,1) && f(3,2) &&& \ddots\\ ~\\ f(4,1) \end{matrix}$$
Is there a way to define a function $f' : \mathbb N \to A$ such the resulting sequence of outputs travels along this grid in the same way?
$$\begin{matrix} f(1,1) && f(1,2) &\color{red}\to &f(1,3) &&f(1,4)& \color{red}\to & f(1,5)\\ \color{red}\downarrow & \color{red}\nearrow && \color{red}\swarrow && \color{red}\nearrow &&\color{red}\swarrow\\ f(2,1) && f(2,2) && f(2,3) \\ & \color{red}\swarrow && \color{red}\nearrow\\ f(3,1) && f(3,2) &&& \ddots\\ \color{red}\downarrow&\color{red}\nearrow\\ f(4,1) \end{matrix}$$
That is, defining $f'$ in terms of $f$ such that
$$ f'(1) = f(1,1)\\ f'(2) = f(2,1) \\ f'(3) = f(1,2) \\ f'(4) = f(1,3) \\ f'(5) = f(2,2) \\ f'(6) = f(3,1) \\ \vdots$$
Given $n\in\mathbb N$ I need to find a way to map to the corresponding pair in $\mathbb N^2$, expressing this only in terms of $n$, but I'm not sure how to do this. I appreciate any assistance.