nashcft's blog

時々何か書く。

Seven More Languages in Seven Weeks: Julia Day 1の演習問題をやった (ずいぶん前に)

間が空きすぎてしまった...
Day 1 の演習自体は前の記事を書いた後すぐにやってはいたのだけど
下書きを書いた後先に進めている間に詰まったか何かして公開しないまま投げてしまったようです (記憶が朧げ)
とりあえず書いた当時のまま晒すだけ晒しておこう...


github.com

設問の中に5x5x5の配列を作れとあって、3次元以上の配列の作り方を知ってから「じゃあ4次元配列を作ったらどうなるんだろう?」と思って試した結果がこちら:

julia> Array(Int64, 5,5,5,5)
5x5x5x5 Array{Int64,4}:
[:, :, 1, 1] =
 4469252560           0  4469252560           0  4469252560
          0  4469251016           0  4469252560           0
 4469255624           0  4469252560           0  4469252560
          0  4469252560           0  4469252560           0
 4469252560           0  4469252560           0  4469252560

[:, :, 2, 1] =
                   0  78152697455975698193556471915367379232  0
     140278440639040  7867888721079460201     3556471915367379232  0
 5417930524443302683  2319735731304618779     3539894578555400480  0
 5129700148190993179  2319735477633097777     3539883321446117664  0
 7868170196776672027  2319735477633097777     5132187517736263739  0

[:, :, 3, 1] =
 0  0                    0  7868170196776672027  2319735477633097777
 0  0                    0  7815269745597569819  2319735477633097777
 0  0      140278440639328  7867888721079460201  2319735477633097777
 0  0  5417930524443302683  2319735731304618779  3556471770077798449
 0  0  5129700148190993179  2319735477633097777  3556471915367379232

[:, :, 4, 1] =
 3556471915367379232  20046507979529531  0  0                    0
 3556471915367379232                  0  0  0                    0
 3556471915367379232                  0  0  0                    0
 3539894578555400480                  0  0  0      140278440639616
 3539883321446117664                  0  0  0  5417930524443302683

[:, :, 5, 1] =
 5129700148190993179  23197354776330977773539883321446117664  0
 7868170196776672027  2319735477633097777          78302376827741  0
 7815269745597569819  2319735477633097777                       0  0
 7867888721079460201  2319735477633097777                       0  0
 2319735731304618779  3556471770077798449                       0  0

[:, :, 1, 2] =
 0                0  54179305244433026833556471770077798449
 0                0  5129700148190993179     3556471915367379232
 0                0  7868170196776672027     3556471915367379232
 0                0  7815269745597569819     3556471915367379232
 0  140278440639904  7867888721079460201     3556471915367379232

[:, :, 2, 2] =
 3539894578555400480  0  0  0      140278440640192
 6710417459114946848  0  0  0  5417930524443302683
        305851882267  0  0  0  5129700148190993179
                   0  0  0  0  7868170196776672027
                   0  0  0  0  7815269745597569819

[:, :, 3, 2] =
 7867888721079460201  2319735477633097777  3556471915367379232  0  0
 2319735731304618779  3556471770077798449  3539894578555400480  0  0
 2319735477633097777  3556471915367379232  1971786226191053088  0  0
 2319735477633097777  3556471915367379232           1194668379  0  0
 2319735477633097777  3556471915367379232                    0  0  0

[:, :, 4, 2] =
 0                    0  78152697455975698193556471915367379232
 0      140278440640480  7867888721079460201     3556471915367379232
 0  5417930524443302683  2319735731304618779     3539894578555400480
 0  5129700148190993179  2319735477633097777     6564943274667159840
 0  7868170196776672027  2319735477633097777                 4666417

[:, :, 5, 2] =
 0  0  0                    0  7868170196776672027
 0  0  0                    0  7815269745597569819
 0  0  0      140278440640768  7867888721079460201
 0  0  0  5417930524443302683  2319735731304618779
 0  0  0  5129700148190993179  2319735477633097777

[:, :, 1, 3] =
 2319735477633097777  3556471915367379232  18227  0  0
 2319735477633097777  3556471915367379232      0  0  0
 2319735477633097777  3556471915367379232      0  0  0
 3556471770077798449  3539894578555400480      0  0  0
 3556471915367379232  3556466417809240352      0  0  0

[:, :, 2, 3] =
                   0  51297001481909931793616772148839854368
                   0  7868170196776672027                      71
                   0  7815269745597569819                       0
     140278440641056  7867888721079460201                       0
 5417930524443302683  2319735731304618779                       0

[:, :, 3, 3] =
 0  0                0  5417930524443302683  2319735731304618779
 0  0                0  5129700148190993179  2319735477633097777
 0  0                0  7868170196776672027  2319735477633097777
 0  0                0  7815269745597569819  2319735477633097777
 0  0  140278440641344  7867888721079460201  2319735477633097777

[:, :, 4, 3] =
 3556471770077798449  3539894578555400480  0  0  0
 3556471915367379232  5129935717922582816  0  0  0
 3556471915367379232                    0  0  0  0
 3556471915367379232                    0  0  0  0
 3556471915367379232                    0  0  0  0

[:, :, 5, 3] =
     140278440641632  78678887210794602013556471915367379232  0
 5417930524443302683  2319735731304618779     3539894578555400480  0
 5129700148190993179  2319735477633097777       20037711886507296  0
 7868170196776672027  2319735477633097777                       0  0
 7815269745597569819  2319735477633097777                       0  0

[:, :, 1, 4] =
 0  0                    0  7815269745597569819  2319735477633097777
 0  0      140278440641920  7867888721079460201  2319735477633097777
 0  0  5417930524443302683  2319735731304618779  3556471770077798449
 0  0  5129700148190993179  2319735477633097777  3556471915367379232
 0  0  7868170196776672027  2319735477633097777  3556471915367379232

[:, :, 2, 4] =
 3556471915367379232  0  0  0                    0
 3556471915367379232  0  0  0                    0
 3539894578555400480  0  0  0      140278440642208
        305904950109  0  0  0  5417930524443302683
                   0  0  0  0  5129700148190993179

[:, :, 3, 4] =
 7868170196776672027  2319735477633097777  3556471915367379232  0  0
 7815269745597569819  2319735477633097777  3556471915367379232  0  0
 7867888721079460201  2319735477633097777  3556471915367379232  0  0
 2319735731304618779  3556471770077798449  6710428716224229664  0  0
 2319735477633097777  3556471915367379232           1194875675  0  0

[:, :, 4, 4] =
 0                    0  51297001481909931793556471915367379232
 0                    0  7868170196776672027     3556471915367379232
 0                    0  7815269745597569819     3556471915367379232
 0      140278440642496  7867888721079460201     3556471915367379232
 0  5417930524443302683  2319735731304618779     1971797483300335904

[:, :, 5, 4] =
 4667227  0  0                0  5417930524443302683
       0  0  0                0  5129700148190993179
       0  0  0                0  7868170196776672027
       0  0  0                0  7815269745597569819
       0  0  0  140278440642784  7867888721079460201

[:, :, 1, 5] =
  2319735731304618779  0  0  0  0
  2319735477633097777  0  0  0  0
 -6917529027641081856  0  0  0  0
 -6917529027641081856  0  0  0  0
                    0  0  0  0  0

[:, :, 2, 5] =
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0

[:, :, 3, 5] =
 140278443538256  0  0  0  0
 140278438868112  0  0  0  0
               0  0  0  0  0
               0  0  0  0  0
               0  0  0  0  0

[:, :, 4, 5] =
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0

[:, :, 5, 5] =
 0                0  140278443539344                0  0
 0                0  140278438866256  140278438864720  0
 0                0  140278443538768  140278438868016  0
 0  140278443538896  140278443540944                0  0
 0  140278438867888                0                0  0

なんでや...
ちなみに5次元配列、6次元配列を作るとちゃんと0で初期化された配列が返ってくる(そこまでしか試していない)。

julia> Array(Int64, 5,5,5,5,5)
5x5x5x5x5 Array{Int64,5}:
[:, :, 1, 1, 1] =
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0

[:, :, 2, 1, 1] =
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0

[:, :, 3, 1, 1] =
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0

[:, :, 4, 1, 1] =
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0

[:, :, 5, 1, 1] =
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0

[:, :, 1, 2, 1] =
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0

...

[:, :, 3, 5, 5] =
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0

[:, :, 4, 5, 5] =
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0

[:, :, 5, 5, 5] =
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0