2018年1月20日土曜日

180120

Ruby


1~9を左右交互に付け加える操作で得られる数字がずっと素数

以下のコードで求めてみた。

require 'prime'

def A(k, n)
  ary = [2, 3, 5, 7]
  p [ary.size, ary]
  (n - 1).times{|i|
    ary1 = []
    ary.each{|a|
      if i % 2 == k
        (1..9).each{|d|
          j = (d.to_s + a.to_s).to_i
          ary1 << j if j.prime?
        }
      else
        # 1の桁が0の素数はない
        (1..9).each{|d|
          j = (a.to_s + d.to_s).to_i
          ary1 << j if j.prime?
        }
      end
    }
    ary = ary1.uniq
    p [ary.size, ary]
  }
end

# 最初左から加える
A(0, 16)
p ''
# 最初右から加える
A(1, 14)

出力結果
[4, [2, 3, 5, 7]]
[11, [13, 23, 43, 53, 73, 83, 17, 37, 47, 67, 97]]
[20, [131, 137, 139, 233, 239, 431, 433, 439, 733, 739, 839, 173, 179, 373, 379, 479, 673, 677, 971, 977]]
[53, [2131, 6131, 2137, 3137, 9137, 4139, 5233, 8233, 2239, 9239, 5431, 8431, 9431, 1433, 3433, 7433, 9433, 1439, 9439, 1733, 3733, 4733, 6733, 9733, 3739, 9739, 5839, 8839, 9839, 6173, 9173, 2179, 5179, 8179, 1373, 3373, 4373, 6373, 6379, 5479, 9479, 3673, 4673, 6673, 7673, 2677, 3677, 8677, 9677, 2971, 6971, 8971, 6977]]
[51, [21313, 21317, 21319, 21377, 21379, 31379, 91373, 41399, 82339, 22391, 22397, 92399, 54311, 54319, 84313, 84317, 84319, 34337, 94331, 94397, 94399, 17333, 37337, 37339, 47339, 67339, 37397, 97397, 58391, 58393, 88397, 91733, 21799, 51797, 81799, 33739, 63737, 63793, 63799, 54799, 94793, 36739, 66733, 66739, 76733, 26777, 36779, 86771, 96779, 29717, 69779]]
[100, [121313, 321313, 421313, 221317, 521317, 621317, 321319, 721319, 521377, 821377, 121379, 721379, 921379, 231379, 291373, 391373, 182339, 782339, 982339, 522391, 822391, 922391, 322397, 622397, 692399, 954319, 784313, 384317, 294397, 594397, 794399, 217333, 317333, 617333, 917333, 637337, 937337, 137339, 337339, 637339, 737339, 247339, 847339, 167339, 767339, 337397, 297397, 697397, 658391, 158393, 758393, 958393, 588397, 688397, 888397, 391733, 991733, 321799, 621799, 351797, 851797, 781799, 633739, 933739, 263737, 663737, 963793, 363799, 963799, 154799, 354799, 454799, 654799, 294793, 594793, 894793, 994793, 136739, 436739, 636739, 936739, 366733, 466733, 666733, 166739, 766739, 676733, 226777, 526777, 926777, 236779, 536779, 936779, 286771, 596779, 229717, 329717, 929717, 269779, 869779]]
[63, [1213133, 3213131, 3213137, 3213139, 4213133, 2213171, 5213171, 5213179, 6213173, 5213773, 5213777, 9213791, 9213797, 2313797, 2313799, 2913733, 2913739, 9223919, 3843179, 2943971, 2173333, 2173337, 6373391, 6373397, 6373399, 2473391, 8473391, 1673393, 6973973, 6583919, 5883971, 5883973, 5883979, 8883971, 8883977, 3217997, 6217993, 6217999, 2637373, 2637379, 6637373, 9637937, 1547993, 3547991, 3547993, 2947939, 1367393, 4367393, 6367391, 6367393, 3667333, 6667337, 6767333, 2267773, 5267771, 9267773, 2367793, 2367797, 9367793, 2867719, 2697797, 8697791, 8697797]]
[76, [23213131, 33213137, 93213137, 13213139, 93213139, 65213171, 95213171, 65213179, 75213179, 15213773, 75213773, 95213773, 35213777, 65213777, 89213791, 99213791, 69213797, 52313797, 92313797, 12313799, 62313799, 42913733, 62913733, 72913733, 12913739, 32913739, 72913739, 92913739, 89223919, 63843179, 52943971, 62943971, 42173333, 76373399, 96373399, 28473391, 31673393, 36973973, 45883979, 98883971, 58883977, 98883977, 76217993, 42637373, 62637373, 92637373, 42637379, 59637937, 69637937, 89637937, 31547993, 91547993, 33547991, 83547991, 12947939, 62947939, 21367393, 31367393, 24367393, 34367393, 66367391, 43667333, 93667333, 86667337, 32267773, 42267773, 62267773, 85267771, 29267773, 59267773, 12367793, 32367793, 62367793, 52367797, 12867719, 28697797]]
[42, [932131391, 652131791, 652131793, 652131797, 692137973, 523137971, 923137973, 123137999, 429137333, 429137339, 629137337, 892239197, 529439717, 963733997, 284733913, 369739739, 458839793, 588839777, 988839779, 426373733, 626373731, 926373731, 926373733, 926373739, 426373799, 696379373, 896379371, 896379373, 896379377, 629479391, 629479393, 213673931, 213673937, 936673337, 866673377, 322677737, 622677733, 852677717, 292677731, 292677739, 323677933, 623677939]]
[43, [5652131791, 7652131793, 9652131793, 5692137973, 3523137971, 3923137973, 3429137333, 5429137339, 6629137337, 9629137337, 2892239197, 8892239197, 9892239197, 6529439717, 8529439717, 7284733913, 2988839779, 8426373733, 3626373731, 6626373731, 9926373731, 9926373733, 1926373739, 3926373739, 6926373739, 9926373739, 6426373799, 4896379373, 7896379373, 8896379377, 9896379377, 3629479391, 3629479393, 5213673931, 2213673937, 2866673377, 6866673377, 2322677737, 9852677717, 9292677731, 1323677933, 4323677933, 6623677939]]
[20, [56521317911, 96521317933, 35231379713, 35231379719, 54291373393, 66291373373, 96291373379, 99263737319, 39263737393, 39263737397, 99263737399, 64263737999, 48963793733, 98963793779, 36294793919, 36294793939, 52136739311, 28666733779, 98526777179, 92926777319]]
[13, [996521317933, 635231379719, 299263737319, 399263737319, 899263737319, 939263737397, 264263737999, 664263737999, 548963793733, 328666733779, 998526777179, 892926777319, 992926777319]]
[4, [6642637379993, 9985267771799, 8929267773197, 9929267773199]]
[4, [36642637379993, 29985267771799, 58929267773197, 88929267773197]]
[1, [889292677731979]]
[0, []]
""
[4, [2, 3, 5, 7]]
[9, [23, 29, 31, 37, 53, 59, 71, 73, 79]]
[30, [223, 523, 823, 229, 829, 929, 131, 331, 431, 631, 137, 337, 937, 353, 653, 853, 953, 359, 659, 859, 271, 571, 971, 173, 373, 673, 773, 179, 379, 479]]
[49, [2237, 2239, 5231, 5233, 5237, 8231, 8233, 8237, 2293, 2297, 8291, 8293, 8297, 9293, 1319, 3313, 3319, 6311, 6317, 1373, 3371, 3373, 9371, 9377, 3533, 3539, 8537, 8539, 9533, 9539, 3593, 6599, 8597, 8599, 2711, 2713, 2719, 5711, 5717, 9719, 1733, 3733, 3739, 6733, 6737, 3793, 3797, 4793, 4799]]
[99, [32237, 52237, 82237, 92237, 12239, 42239, 95231, 15233, 45233, 95233, 25237, 85237, 38231, 58231, 18233, 78233, 38237, 58237, 88237, 42293, 32297, 62297, 92297, 28297, 98297, 39293, 89293, 21319, 31319, 13313, 43313, 63313, 43319, 93319, 56311, 86311, 26317, 81373, 91373, 23371, 93371, 39371, 69371, 89371, 99371, 59377, 99377, 33533, 63533, 23539, 28537, 58537, 18539, 48539, 68539, 78539, 89533, 59539, 69539, 23593, 53593, 36599, 56599, 86599, 28597, 68597, 98597, 52711, 12713, 32713, 32719, 42719, 72719, 55711, 85711, 25717, 55717, 65717, 85717, 95717, 39719, 99719, 91733, 33739, 93739, 66733, 76733, 26737, 56737, 96737, 43793, 63793, 33797, 24793, 64793, 84793, 94793, 24799, 54799]]
[74, [522371, 522373, 822379, 122393, 122399, 422393, 952313, 582317, 582319, 182333, 182339, 782339, 382373, 582371, 882377, 922973, 282973, 282977, 982973, 892933, 213193, 633133, 433193, 933199, 563113, 563117, 563119, 863119, 263171, 913739, 233713, 393713, 893719, 593777, 993779, 635333, 635339, 235397, 285377, 685393, 895333, 535937, 535939, 565997, 865993, 285977, 285979, 685973, 985973, 985979, 127133, 127139, 327133, 327193, 257171, 257177, 917333, 337397, 667333, 767339, 267373, 567377, 637933, 637937, 637939, 337973, 247939, 847933, 847937, 247991, 247993, 247997, 247999, 547999]]
[101, [2522371, 6522371, 7822379, 5122393, 5422393, 6952313, 1582319, 9582319, 2182333, 8182333, 5182339, 6782339, 3382373, 2882377, 5882377, 6882377, 2922973, 3922973, 4282973, 3282977, 5982973, 8982973, 1633133, 8433193, 1933199, 3933199, 9933199, 4563113, 2563117, 8563117, 9563117, 1563119, 6863119, 2263171, 6263171, 2913739, 8913739, 3393713, 1893719, 3893719, 2593777, 6593777, 8593777, 9593777, 3993779, 3285377, 8285377, 4685393, 7895333, 2535937, 1535939, 5565997, 3865993, 9865993, 2285977, 6285977, 9285977, 3285979, 3685973, 2985973, 6985973, 9985973, 2985979, 2127133, 3127139, 5127139, 1327133, 3327193, 9327193, 3257171, 5257171, 6257171, 8257177, 2917333, 2337397, 3667333, 7667333, 5767339, 9767339, 2567377, 6637933, 2637937, 3637937, 9637937, 3637939, 4637939, 3337973, 5337973, 9337973, 9247939, 1847933, 4847933, 2847937, 6847937, 2247991, 8247991, 9247993, 5247997, 8247997, 6247999, 9247999]]
[71, [25223711, 25223713, 78223799, 69523133, 95823193, 21823339, 81823333, 81823337, 33823739, 58823773, 58823777, 29229737, 39229733, 59829733, 25631173, 85631177, 85631179, 15631199, 22631711, 33937133, 33937139, 18937199, 25937773, 85937773, 78953333, 25359371, 55659971, 55659979, 38659939, 22859773, 22859779, 62859773, 92859773, 92859779, 32859791, 69859733, 69859739, 29859793, 29859799, 21271331, 21271339, 31271399, 51271397, 51271399, 33271937, 33271939, 93271939, 32571713, 52571711, 52571719, 29173337, 23373979, 36673331, 36673333, 57673391, 97673399, 66379337, 26379373, 26379377, 96379373, 36379397, 46379393, 93379733, 22479911, 22479913, 22479917, 82479911, 92479931, 92479939, 82479979, 92479997]]
[72, [325223713, 425223713, 625223713, 925223713, 869523133, 195823193, 395823193, 321823339, 181823333, 381823333, 233823739, 333823739, 533823739, 458823773, 558823777, 958823777, 239229733, 925631173, 985631177, 185631179, 685631179, 815631199, 533937133, 933937133, 333937139, 425937773, 978953333, 655659971, 155659979, 722859773, 722859779, 992859773, 992859779, 232859791, 632859791, 669859733, 969859739, 129859799, 329859799, 429859799, 221271331, 921271331, 921271339, 451271399, 733271939, 793271939, 632571713, 932571713, 452571719, 229173337, 929173337, 623373979, 723373979, 536673331, 136673333, 636673333, 857673391, 397673399, 726379373, 826379377, 696379373, 896379373, 846379393, 293379733, 593379733, 122479913, 922479913, 392479931, 692479939, 482479979, 592479997, 992479997]]
[35, [3252237133, 8695231331, 3818233333, 2338237399, 5338237391, 4588237733, 5588237771, 2392297337, 8156311993, 6556599713, 9928597793, 2328597919, 6698597333, 2212713317, 9212713313, 9212713399, 4512713993, 4525717193, 2291733377, 9291733379, 5366733311, 1366733339, 6366733337, 8576733917, 7263793739, 8263793771, 8263793773, 8963793737, 8963793739, 2933797331, 5933797333, 9224799137, 9224799139, 3924799313, 5924799971]]
[28, [73252237133, 13818233333, 63818233333, 42338237399, 64588237733, 98156311993, 89928597793, 22212713317, 32212713317, 39212713313, 89212713313, 49212713399, 69212713399, 99212713399, 94512713993, 92291733377, 29291733379, 59291733379, 89291733379, 99291733379, 31366733339, 68263793771, 88263793771, 38263793773, 22933797331, 65933797333, 35924799971, 65924799971]]
[9, [732522371333, 638182333331, 981563119937, 981563119939, 899285977939, 313667333393, 682637937713, 229337973317, 659337973331]]
[4, [6638182333331, 5981563119937, 8313667333393, 2682637937713]]
[0, []]

0 件のコメント:

コメントを投稿

注: コメントを投稿できるのは、このブログのメンバーだけです。