1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

シクシク素数列Advent Calendar 2018

Day 1

シクシク素数アドベントカレンダー Ruby 編

Last updated at Posted at 2018-11-30

シクシク素数アドベントカレンダー Advent Calendar 2018 の 1 日目です

プログラム(Ruby)

require "prime"

😭prime = Enumerator.new do |y|
  a = 1
  loop do
    a += 1
    loop { a.prime? && a.to_s.match(/[49]/) ? break : a += 1 }
    y << a
  end
end

print 😭prime.take(ARGV.first.to_i).join(",")

出力例

$ ruby test.rb 2
19,29
$ ruby test.rb 4
19,29,41,43,47,59,79,89,97
$ ruby test.rb 100
19,29,41,43,47,59,79,89,97,109,139,149,179,191,193,197,199,229,239,241,269,293,347,349,359,379,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,509,541,547,569,593,599,619,641,643,647,659,691,709,719,739,743,769,797,809,829,839,859,907,911,919,929,937,941,947,953,967,971,977,983,991,997,1009,1019,1039,1049,1069,1091,1093,1097,1109,1129,1193,1229,1249,1259,1279,1289,1291,1297,1319
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?