Ulam spiral (for primes): Difference between revisions
Content added Content deleted
m (→counter-clockwise: fixed closing tag for the OUTPUT template.) |
No edit summary |
||
Line 2,887: | Line 2,887: | ||
██ ██ ██ ██ ██ |
██ ██ ██ ██ ██ |
||
</pre> |
</pre> |
||
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
|||
<lang Mathematica>ClearAll[iCCWSpiralEast] |
|||
iCCWSpiralEast[n_Integer]:=Table[(1/2 (-1)^# ({1,-1} (Abs[#^2-t]-#)+#^2-t-Mod[#,2])&)[Round[Sqrt[t]]],{t,0,n-1}] |
|||
n=20 |
|||
start=1; |
|||
pts=iCCWSpiralEast[n^2]; |
|||
pts=Pick[pts,PrimeQ[start+Range[n^2]-1],True]; |
|||
grid=Table[({i,j}/.(Alternatives@@pts)->"#")/.{_,_}->" ",{j,Round[n/2],-Round[n/2],-1},{i,-Round[n/2],Round[n/2],1}]; |
|||
Grid[grid]</lang> |
|||
{{out}} |
|||
<pre> * * * |
|||
* * * * |
|||
* * * * |
|||
* * * |
|||
* * * |
|||
* * * * |
|||
* * * |
|||
* * * * * * |
|||
* * * * * * |
|||
* * * |
|||
* * ** * * * |
|||
* * * |
|||
* * |
|||
* * * * * * |
|||
* * * * * |
|||
* * |
|||
* * * * * |
|||
* * |
|||
* * * |
|||
* * * * </pre> |
|||
=={{header|Nim}}== |
=={{header|Nim}}== |