0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ウラムの螺旋(Mathematica)

Posted at

 整数を螺旋状に並べて・・・
1.png

素数のマスを黒く塗る
2.png

 行列を4つに分けて、数値をずらす&回転して足し合わせると螺旋状の整数行列になります。素数判定は組み込み関数のPrimeQを使用します↓

UlamSpiral
n = 100; (* 2n+1 x 2n+1 *)

{m1, m2, m3, m4} = 
  Table[If[
      j + 1 <= i <= 2 n + 2 - j, (2 (n - j + 1) - 1)^2 + 
       2 # (n - j + 1) + i - j - 1, 0], {i, 2 n + 1}, {j, 
      2 n + 1}] & /@ {0, 1, 2, 3};
m2 = Reverse[Transpose[m2]];
m3 = Reverse[Transpose[Reverse[Transpose[m3]]]];
m4 = Transpose[Reverse[m4]];
m = m1 + m2 + m3 + m4;

a = Table[If[PrimeQ[m[[i, j]]], 1, 0], {i, 2 n + 1}, {j, 2 n + 1}];
ArrayPlot[a]

ウラムの螺旋(201x201)
3.png

ウラムの螺旋(401x401)
4.png

 素数が多く分布する斜め45度の直線がはっきり見て取れます。同じ密度でランダムに奇数を黒く塗った場合、このようには見えません。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?