Kuvunguza izinombolo

Ezinsukwini ezimbalwa ezedlule, bengifunda lo mbuzo olandelayo ku- StackExchange mayelana nokuvunguza kwama-integer. Sifuna ifomula evaliwe yezixhumanisi zesici se- \(n\) -th kokuphindaphindekayo okulandelayo, okusuka kumsuka kuye ngaphandle kuqhubekele phambili kuye ekugcineni okungapheli:

..  9 10 11 12
23  8  1  2 13
22  7  0  3 14
21  6  5  4 15
20 19 18 17 16

Okokuqala sihlukanisa izinombolo zemvelo ngamaqembu alandelayo:

$$G_1 = \{ 1,...,8 \}\\G_2 = \{ 9, ..., 24 \}\\G_3 = \{ 25, ... 48 \}\\...\\G_k = \left\{ (2k-1)^2, (2k+1)^2 - 1 \right\}$$

Siyabiza

$$a^2 = \left(\left \lfloor \left( \frac{\left \lfloor \sqrt{n} \right \rfloor + 1}{2} \right) \right \rfloor \cdot 2 - 1 \right)^2$$

inombolo yokuqala eqenjini.

Ngaphakathi kweqembu kunamaqenjana amane osayizi abalinganayo \(G_1\) \(g_1 = \{ 1,2 \}, g_2 = \{ 3,4 \}, g_3 = \{ 5,6 \}, g_4 = \{7,8\}\) ). Uma \(n\) isuka eqenjini elilodwa liye kwelilandelayo, inkomba yendlela yokuvunguza (ngokwewashi kusibonelo sethu) nayo iyashintshwa ngasikhathi sinye. Sithola umkhombandlela wamanje \( b \in \{0,1,2,3\} \) ngokuhlukanisa indawo \(na^2\) ngaphakathi kweqembu ngenombolo yezinto eziseqenjini elincane:

$$b = \left \lfloor \frac{ n - a^2 }{ \text{abs}\left( a \right) + 1 } \right \rfloor$$

Manje \(g_n\) into yokuqala ngaphakathi kweqembu elincane \(g_n\) ngokungeza okuphindwe kabili \(b\) kwenombolo \(a+1\) yezakhi ngaphakathi kweqembu kunombolo yokuqala \(a^2\):

$$c = a^2 + b \cdot (a+1)$$

Manje sesinganquma ngokubheka okulula:

$$x_{right} = \left(n - c - \frac{ a + 1 }{2}+1\right),\, y_{right} = \left(\frac{ a + 1 }{2}\right) \\ x_{bottom} = \left(\frac{ a + 1 }{2}\right),\, y_{bottom} = (-1) \cdot \left( n - c - \frac{ a + 1 }{2}+1\right) \\ x_{left} = (-1) \cdot \left(n - c - \frac{ a + 1 }{2}+1\right),\, y_{left} = (-1) \cdot \left(\frac{ a + 1 }{2}\right) \\ x_{top} = (-1) \cdot \left(\frac{ a + 1 }{2}\right),\, y_{top} = \left( n - c - \frac{ a + 1 }{2}+1\right)$$

Sifuna ukumela \(f(n)\) ngesethulo esivaliwe futhi ngaphandle kokuhlukaniswa kwamacala. Sisebenzisa umsebenzi weSignum, ngichaze inqubo lapha . Ukuze sithole ifomula emsulwa njengomsebenzi we \(n\) , sithola:

Ngosizo lwe- SVG.js , siyabona kulokhu ukubona okuncane ukuthi yonke into iyasebenza ngempela:

See the Pen ulam spiral by David Vielhuber (@vielhuber) on CodePen.

Ukuvutha kwaziwa nangokuthi ukuvunguza kuka-Ulam futhi kunokuhlobana okuthokozisayo nezinombolo eziyinhloko.

Emuva