Cyclops numbers: Difference between revisions

(→‎{{header|ALGOL 68}}: Use ALGOL 68-primes)
Line 2,102:
</pre>
 
=={{header|Ruby}}==
<lang ruby>require 'prime'
 
NONZEROS = %w(1 2 3 4 5 6 7 8 9)
 
cyclopes = Enumerator.new do |y|
(0..).each do |n|
NONZEROS.repeated_permutation(n) do |lside|
NONZEROS.repeated_permutation(n) do |rside|
y << (lside.join + "0" + rside.join).to_i
end
end
end
end
 
prime_cyclopes = Enumerator.new {|y| cyclopes.each {|c| y << c if c.prime?} }
blind_prime_cyclopes = Enumerator.new {|y| prime_cyclopes.each {|c| y << c if c.to_s.delete("0").to_i.prime?} }
palindromic_prime_cyclopes = Enumerator.new {|y| prime_cyclopes.each {|c| y << c if c.to_s == c.to_s.reverse} }
 
n, m = 50, 10_000_000
["cyclopes", "prime cyclopes", "blind prime cyclopes", "palindromic prime cyclopes"].zip(
[cyclopes, prime_cyclopes, blind_prime_cyclopes, palindromic_prime_cyclopes]).each do |name, enum|
cycl, idx = enum.each_with_index.detect{|n, i| n > m}
puts "The first #{n} #{name} are: \n#{enum.take(n).to_a}\nFirst #{name} term > #{m}: #{cycl} at index: #{idx}.", ""
end
</lang>
{{out}}
<pre>The first 50 cyclopes are:
[0, 101, 102, 103, 104, 105, 106, 107, 108, 109, 201, 202, 203, 204, 205, 206, 207, 208, 209, 301, 302, 303, 304, 305, 306, 307, 308, 309, 401, 402, 403, 404, 405, 406, 407, 408, 409, 501, 502, 503, 504, 505, 506, 507, 508, 509, 601, 602, 603, 604]
First cyclopes term > 10000000: 111101111 at index: 538084.
 
The first 50 prime cyclopes are:
[101, 103, 107, 109, 307, 401, 409, 503, 509, 601, 607, 701, 709, 809, 907, 11027, 11047, 11057, 11059, 11069, 11071, 11083, 11087, 11093, 12011, 12037, 12041, 12043, 12049, 12071, 12073, 12097, 13033, 13037, 13043, 13049, 13063, 13093, 13099, 14011, 14029, 14033, 14051, 14057, 14071, 14081, 14083, 14087, 15013, 15017]
First prime cyclopes term > 10000000: 111101129 at index: 39319.
 
The first 50 blind prime cyclopes are:
[101, 103, 107, 109, 307, 401, 503, 509, 601, 607, 701, 709, 809, 907, 11071, 11087, 11093, 12037, 12049, 12097, 13099, 14029, 14033, 14051, 14071, 14081, 14083, 14087, 15031, 15053, 15083, 16057, 16063, 16067, 16069, 16097, 17021, 17033, 17041, 17047, 17053, 17077, 18047, 18061, 18077, 18089, 19013, 19031, 19051, 19073]
First blind prime cyclopes term > 10000000: 111101161 at index: 11393.
 
The first 50 palindromic prime cyclopes are:
[101, 16061, 31013, 35053, 38083, 73037, 74047, 91019, 94049, 1120211, 1150511, 1160611, 1180811, 1190911, 1250521, 1280821, 1360631, 1390931, 1490941, 1520251, 1550551, 1580851, 1630361, 1640461, 1660661, 1670761, 1730371, 1820281, 1880881, 1930391, 1970791, 3140413, 3160613, 3260623, 3310133, 3380833, 3460643, 3470743, 3590953, 3670763, 3680863, 3970793, 7190917, 7250527, 7310137, 7540457, 7630367, 7690967, 7750577, 7820287]
First palindromic prime cyclopes term > 10000000: 114808411 at index: 66.
</pre>
=={{header|Sidef}}==
<lang ruby>func cyclops_numbers(base = 10) {
1,149

edits