シクシク素数アドベントカレンダー 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