NotebookDirectory[]

A bijection from ℕ onto ℕxℕ.

The next formula gives an explicit form of  the "repeat sequence".

Clear[r,n];
r[n_]:=Floor[(Sqrt[2 n])+(1/2)]

Table[r[n],{n,1,50}]

Recursive formula for the above repeat sequence is

Clear[rr];rr[1]=1; rr[n_]:=rr[n]=1+rr[n-rr[n-1]]

rr[2]

Table[rr[k],{k,1,120}]

Table[{k,rr[k]},{k,1,120}]

The following formula defines the sequence of triangular numbers.

Clear[T,n];
T[n_]:=(1/2)n(n+1)

Table[T[n],{n,0,50}]

Now, we can give an explicit formula for a bijection from ℕ onto ℕxℕ.

Clear[n,Bf];
Bf[n_]:={(n-T[r[n]-1]),(T[r[n]]-n+1)}

Bf[179]

This is the table of the first 100 values of Bf :

Table[Bf[k],{k,1,100}]

The inverse of the function Bf is the following function

Clear[Af,s,t];
(* Af[{s_,t_}]:=(((s+t-2)(s+t-1))/2)+s *) 
Af[{s_,t_}]:=(((s+t-1)(s+t))/2)-t+1

Af[{1,1}]

Af[{1,2}]

Af[{2,1}]

Af[{8,12}]

To illustrate that the functions Bf and  Af are inverses of each other calculate

First Af[Bf[n]] for many values

Af[Bf[12]]

Bf[Af[{123,54}]]

Now do it for 100 values.

Table[{Af[Bf[k]],k},{k,1,100}]

Now ask Mathematica to confirm that the composition is equal to the identity function for the first 100 values:

Table[Af[Bf[k]]==k,{k,1,100}]

Let Mathematica do checking

Apply[And,Table[Af[Bf[k]]==k,{k,1,100}]]

Pay attention, the table below is large:

Apply[And,Table[Af[Bf[k]]==k,{k,1,100000}]]

Now Bf[Af[{s,t}]] for many values

Bf[Af[{134,216}]]

Flatten[Table[Bf[Af[{j,k}]]=={j,k},{k,1,10},{j,1,10}],1]

Or, many more values, with Mathematica doing the checking

Apply[And,Flatten[Table[Bf[Af[{j,k}]]=={j,k},{k,1,500},{j,1,500}],1]]

The following two functions will help illustrate how listing of points in ℕxℕ works in the coordinate system.

Clear[Illustrate,Illustrate1,Illustrate2,s,t,m,n];

Illustrate[m_,n_]:=Graphics[{
{Thickness[0.004],GrayLevel[0.7],{Line[{{#,-1},{#,100}}],Line[{{-1,#},{100,#}}]}&/@Range[0,30]},
{PointSize[0.04],Point[Bf[#]]&/@Range[1,n]},
{Text[Af[Bf[#]],Bf[#],BaseStyle->{FontSize->7,FontColor->White,FontWeight->"Bold"}]}&/@Range[1,m]
}] 

Illustrate1[n_]:=Graphics[{
{Thickness[0.004],GrayLevel[0.7],{Line[{{#,-1},{#,100}}],Line[{{-1,#},{100,#}}]}&/@Range[0,30]},
{PointSize[0.04],Point[Bf[n]]},
{Text[Af[Bf[n]],Bf[n],BaseStyle->{FontSize->7,FontColor->White,FontWeight->"Bold"}]}
}] 

Illustrate2[{s_,t_}]:=Graphics[{
{Thickness[0.004],GrayLevel[0.7],{Line[{{#,-1},{#,100}}],Line[{{-1,#},{100,#}}]}&/@Range[0,30]},
{PointSize[0.04],Point[{s,t}]},
{Text[Af[{s,t}],{s,t},BaseStyle->{FontSize->7,FontColor->White,FontWeight->"Bold"}]}
}]

Show[
Illustrate1[216],
PlotRange->{{0.5,20.5},{0.5,20.5}},Frame-> True,AspectRatio->Automatic,ImageSize->350,FrameTicks->{Range[1,20],Range[1,20],{},{}}
]

Show[
Illustrate2[{6,14}],
PlotRange->{{0.5,20.5},{0.5,20.5}},Frame-> True,AspectRatio->Automatic,ImageSize->350,FrameTicks->{Range[1,20],Range[1,20],{},{}}
]

Show[
Illustrate1[177],
PlotRange->{{0.5,20},{0.5,20}},Frame-> True,AspectRatio->Automatic,ImageSize->350,FrameTicks->{Range[1,20],Range[1,20],{},{}}
]

Now the animation of listing of the first two hundred points

ListAnimate[Table[Show[
Illustrate[n,n],
PlotRange->{{0.5,20.5},{0.5,20.5}},Frame-> True,AspectRatio->Automatic,ImageSize->350,FrameTicks->{Range[1,20],Range[1,20],{},{}}
],{n,1,200}]]

Show[
Illustrate[685,685],
PlotRange->{{0.5,20.5},{0.5,20.5}},Frame-> True,AspectRatio->Automatic,ImageSize->350,FrameTicks->{Range[1,20],Range[1,20],{},{}}
]

Table[Table[Af[{m,n}],{m,1,10}],{n,1,10}]//TableForm

FindSequenceFunction[{1,2,4,7,11}]