Ukujikeleza kwamanani

Kwezi ntsuku zimbalwa zidlulileyo, bendiphanda lo mbuzo ulandelayo kwiStackExchange malunga nomoya opheleleyo . Sijonge ifomula evaliweyo yolungelelwaniso lwe \(n\) -th element in the integer spiral elandelayo, esukela kwimvelaphi ngaphandle nangaphezulu kwaye iqhubeke iye kubunzulu:

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

Kuqala sahlulahlula amanani endalo kula maqela 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$$

inani lokuqala kwiqela.

Kwakwesi iqela kukho subgroups ezine ezilinganayo \(G_1\) kuba \(G_1\) nto \(g_1 = \{ 1,2 \}, g_2 = \{ 3,4 \}, g_3 = \{ 5,6 \}, g_4 = \{7,8\}\) ). Ukuba \(n\) ukusuka kwelinye iqela ukuya kwelilandelayo, umkhombandlela kwindlela yomoya (ngokwewotshi kumzekelo wethu) uyatshintshwa kwangaxeshanye. Sifumana umkhombandlela wangoku \( b \in \{0,1,2,3\} \) ngokwahlula indawo \(na^2\) ngaphakathi kweqela ngenani lezinto kwiqela elincinci:

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

Ngoku sinokumisela into yokuqala ngaphakathi kweqelana \(g_n\) ngokongeza izinto ezininzi \(b\) zenani \(a+1\) lezinto ezikweli qela kwinani lokuqala \(a^2\):

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

Ngoku sinokumisela ngokujonga ngokulula:

$$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)\) kwisimeli esivaliweyo kwaye nangaphandle kwetyala. Sisebenzisa umsebenzi weSignum, ndichaze inkqubo apha . Ukuze sifumane ifomyula emsulwa njengomsebenzi \(n\) , sifumana:

Ngoncedo lweSVG.js , sinokubona kolu boniso lincinci lokuba yonke loo nto iyasebenza:

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

Ukwanda kwaziwa ngokuba kukujikeleza kuka-Ulam kwaye kunolwalamano olonwabisayo kumanani aphambili.

Emva