Cyclops numbers: Difference between revisions

Added FreeBASIC
(Added FreeBASIC)
 
(33 intermediate revisions by 15 users not shown)
Line 40:
 
 
 
=={{header|11l}}==
{{trans|C++}}
 
<syntaxhighlight lang="11l">
F print50(arr, width = 8)
L(n) arr
print(commatize(n).rjust(width), end' I (L.index + 1) % 10 == 0 {"\n"} E ‘’)
 
F is_cyclops(=n)
I n == 0
R 1B
V m = n % 10
V count = 0
L m != 0
count++
n I/= 10
m = n % 10
n I/= 10
m = n % 10
L m != 0
count--
n I/= 10
m = n % 10
R n == 0 & count == 0
 
F is_prime(p)
I p < 2 | p % 2 == 0
R p == 2
L(i) (3 .. Int(sqrt(p))).step(2)
I p % i == 0
R 0B
R 1B
 
F is_palindromic(d)
R String(d) == reversed(String(d))
 
[Int] arr
 
print(‘The first 50 cyclops numbers are:’)
L(i) 0..
I is_cyclops(i)
arr.append(i)
I arr.len == 50
L.break
print50(arr)
 
print("\nThe first 50 prime cyclops numbers are:")
arr.clear()
L(i) 0..
I is_cyclops(i) & is_prime(i)
arr.append(i)
I arr.len == 50
L.break
print50(arr)
 
print("\nThe first 50 blind prime cyclops numbers are:")
arr.clear()
L(i) 0..
I is_cyclops(i) & is_prime(i)
V istr = String(i)
V mid = istr.len I/ 2
I is_prime(Int(istr[0 .< mid]‘’istr[mid + 1 ..]))
arr.append(i)
I arr.len == 50
L.break
print50(arr)
 
print("\nThe first 50 palindromic prime cyclops numbers are:")
arr.clear()
L(i) 0..
I is_cyclops(i) & is_prime(i) & is_palindromic(i)
arr.append(i)
I arr.len == 50
L.break
print50(arr, 11)
</syntaxhighlight>
 
{{out}}
<pre>
The first 50 cyclops numbers 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
 
The first 50 prime cyclops numbers are:
101 103 107 109 307 401 409 503 509 601
607 701 709 809 907 11,027 11,047 11,057 11,059 11,069
11,071 11,083 11,087 11,093 12,011 12,037 12,041 12,043 12,049 12,071
12,073 12,097 13,033 13,037 13,043 13,049 13,063 13,093 13,099 14,011
14,029 14,033 14,051 14,057 14,071 14,081 14,083 14,087 15,013 15,017
 
The first 50 blind prime cyclops numbers are:
101 103 107 109 307 401 503 509 601 607
701 709 809 907 11,071 11,087 11,093 12,037 12,049 12,097
13,099 14,029 14,033 14,051 14,071 14,081 14,083 14,087 15,031 15,053
15,083 16,057 16,063 16,067 16,069 16,097 17,021 17,033 17,041 17,047
17,053 17,077 18,047 18,061 18,077 18,089 19,013 19,031 19,051 19,073
 
The first 50 palindromic prime cyclops numbers are:
101 16,061 31,013 35,053 38,083 73,037 74,047 91,019 94,049 1,120,211
1,150,511 1,160,611 1,180,811 1,190,911 1,250,521 1,280,821 1,360,631 1,390,931 1,490,941 1,520,251
1,550,551 1,580,851 1,630,361 1,640,461 1,660,661 1,670,761 1,730,371 1,820,281 1,880,881 1,930,391
1,970,791 3,140,413 3,160,613 3,260,623 3,310,133 3,380,833 3,460,643 3,470,743 3,590,953 3,670,763
3,680,863 3,970,793 7,190,917 7,250,527 7,310,137 7,540,457 7,630,367 7,690,967 7,750,577 7,820,287
</pre>
 
=={{header|ALGOL 68}}==
Generates the sequence.
{{libheader|ALGOL 68-primes}}
Note the source of the ALGOL 68-primes library is on a Rosetta Code linked from the above.
<lang algol68>BEGIN # show cyclops numbers - numbers with a 0 in the middle and no other 0 digits #
<syntaxhighlight lang="algol68">BEGIN # show cyclops numbers - numbers with a 0 in the middle and no other 0 digits #
INT max prime = 100 000;
# sieve the primes to max prime #
Line 158 ⟶ 267:
print cyclops( first blind prime cyclops, "blind prime cyclops numbers", 10 );
print cyclops( first palindromic prime cyclops, "palindromic prime cyclops numbers", 10 )
END</langsyntaxhighlight>
{{out}}
<pre>
Line 189 ⟶ 298:
3680863 3970793 7190917 7250527 7310137 7540457 7630367 7690967 7750577 7820287
</pre>
 
=={{header|AppleScript}}==
<syntaxhighlight lang="applescript">on task()
script o
property cyclopses : {}
property primeCyclopses : {}
property blindPrimeCyclopses : {}
property palindromicPrimeCyclopses : {}
on add1(digitList)
set carry to 1
repeat with i from (count digitList) to 1 by -1
set columnSum to (digitList's item i) + carry
if (columnSum < 10) then
set digitList's item i to columnSum
return false -- Finish and indicate "no carry".
end if
-- Otherwise set this digit to 1 instead of to 0 and "carry" on. ;)
set digitList's item i to 1
end repeat
return true
end add1
on intFromDigits(digitList)
if (digitList = {}) then return 0
set n to digitList's beginning
repeat with i from 2 to (count digitList)
set n to n * 10 + (digitList's item i)
end repeat
return n
end intFromDigits
on store(cyclops, lst, counter)
if (counter < 51) then
set lst's end to cyclops
else if (cyclops > 10000000) then
set lst's end to {cyclops, counter}
return false -- No more for this list, thanks.
end if
return true
end store
end script
set {leftDigits, rightDigits, rightless, shiftFactor} to {{}, {}, 0, 10}
set {cRef, pcRef, bpcRef, ppcRef} to {a reference to o's cyclopses, ¬
a reference to o's primeCyclopses, a reference to o's blindPrimeCyclopses, ¬
a reference to o's palindromicPrimeCyclopses}
set {cCount, pcCount, bpcCount, ppcCount} to {0, 0, 0, 0}
set {cActive, pcActive, bpcActive, ppcActive} to {true, true, true, true}
repeat while ((bpcActive) or (ppcActive))
set |right| to o's intFromDigits(rightDigits)
set cyclops to rightless + |right|
if (cActive) then
set cCount to cCount + 1
set cActive to o's store(cyclops, cRef, cCount)
end if
if (isPrime(cyclops)) then
if (pcActive) then
set pcCount to pcCount + 1
set pcActive to o's store(cyclops, pcRef, pcCount)
end if
if (bpcActive) then
set blinded to rightless div 10 + |right|
if (isPrime(blinded)) then
set bpcCount to bpcCount + 1
set bpcActive to o's store(cyclops, bpcRef, bpcCount)
end if
end if
if ((ppcActive) and (rightDigits = stigiDtfel)) then
set ppcCount to ppcCount + 1
set ppcActive to o's store(cyclops, ppcRef, ppcCount)
end if
end if
if (o's add1(rightDigits)) then
-- Adding 1 to rightDigits produced a carry. Add 1 to leftDigits too.
if (o's add1(leftDigits)) then
-- Also carried. Extend both lists by 1 digit.
set {leftDigits's beginning, rightDigits's beginning} to {1, 1}
set shiftFactor to shiftFactor * 10
end if
set rightless to (o's intFromDigits(leftDigits)) * shiftFactor
set stigiDtfel to leftDigits's reverse
end if
end repeat
set output to {}
repeat with this in {{"", o's cyclopses}, {"prime ", o's primeCyclopses}, ¬
{"blind prime ", o's blindPrimeCyclopses}, ¬
{"palindromic prime ", o's palindromicPrimeCyclopses}}
set {type, cyclopses} to this
set output's end to linefeed & "First 50 " & type & "cyclops numbers:"
repeat with i from 1 to 50 by 10
set row to {}
repeat with j from i to (i + 9)
set row's end to (" " & cyclopses's item j)'s text -7 thru -1
end repeat
set output's end to join(row, " ")
end repeat
set {nth, n} to cyclopses's end
set output's end to "The first such number > ten million is the " & n & "th: " & nth
end repeat
join(output, linefeed)
end task
 
on isPrime(n)
if (n < 4) then return (n > 1)
if ((n mod 2 is 0) or (n mod 3 is 0)) then return false
repeat with i from 5 to (n ^ 0.5) div 1 by 6
if ((n mod i is 0) or (n mod (i + 2) is 0)) then return false
end repeat
return true
end isPrime
 
on join(lst, delim)
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to delim
set txt to lst as text
set AppleScript's text item delimiters to astid
return txt
end join
 
task()</syntaxhighlight>
 
{{output}}
<syntaxhighlight lang="applescript">"
First 50 cyclops numbers:
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
The first such number > ten million is the 538085th: 111101111
 
First 50 prime cyclops numbers:
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
The first such number > ten million is the 39320th: 111101129
 
First 50 blind prime cyclops numbers:
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
The first such number > ten million is the 11394th: 111101161
 
First 50 palindromic prime cyclops numbers:
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
The first such number > ten million is the 67th: 114808411"</syntaxhighlight>
 
=={{header|Arturo}}==
 
<lang<syntaxhighlight lang="rebol">cyclops?: function [n][
digs: digits n
all? @[
Line 236 ⟶ 502:
loop split.every:10 first.n: 50 select candidates 'x -> and? [prime? x][cyclops? x] 'row [
print map to [:string] row 'item -> pad item 7
]</langsyntaxhighlight>
 
{{out}}
Line 269 ⟶ 535:
 
=={{header|AWK}}==
<<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f CYCLOPS_NUMBERS.AWK
BEGIN {
Line 326 ⟶ 592:
printf("\n")
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 359 ⟶ 625:
3680863 3970793 7190917 7250527 7310137 7540457 7630367 7690967 7750577 7820287
</pre>
 
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<syntaxhighlight lang="bbcbasic"> M% = 50
E% = 10000000
DIM Res%(3, M%-1), Task$(3), Exc%(3), Idx%(3), N% 15
 
Size%=3
WHILE TRUE
Overflow%=FALSE
Last%=Size% - 1
Zero%=Last% / 2
$$N%=STRING$(Size%, "1")
N%?Zero%=48
REPEAT
V%=VAL$$N%
IF Exc%(0) == 0 THEN
Idx%(0)+=1
IF Idx%(0) < M% Res%(0, Idx%(0))=V%
IF V% > E% Exc%(0)=V%
ENDIF
IF Exc%(2) == 0 THEN
IF FNIsPrime(V%) THEN
IF Exc%(1) == 0 THEN
IF Idx%(1) < M% Res%(1, Idx%(1))=V%
Idx%(1)+=1
IF V% > E% Exc%(1)=V%
ENDIF
IF FNIsPrime(VAL(LEFT$($$N%, Zero%) + $$(N% + Zero% + 1))) THEN
IF Idx%(2) < M% Res%(2, Idx%(2))=V%
Idx%(2)+=1
IF V% > E% Exc%(2)=V%
ENDIF
ENDIF
ENDIF
FOR I%=0 TO Zero%-1
IF N%?I% <> N%?(Last%-I%) EXIT FOR
NEXT
IF I% == Zero% IF FNIsPrime(V%) THEN
IF Idx%(3) < M% Res%(3, Idx%(3))=V%
Idx%(3)+=1
IF V% > E% Exc%(3)=V% EXIT WHILE
ENDIF
D%=Last%
N%?D%+=1
WHILE N%?D% > 57
N%?D%=49
D%-=1 IF D% == Zero% D%-=1
IF D% < 0 Overflow%=TRUE EXIT WHILE
N%?D%+=1
ENDWHILE
UNTIL Overflow%
Size%+=2
ENDWHILE
 
@%=&20008
Task$()="", " prime", " blind prime", " palindromic prime"
FOR I%=0 TO 3
PRINT "The first ";M% Task$(I%) " cyclop numbers are:"
FOR J%=0 TO M%-1
PRINT Res%(I%, J%),;
IF J% MOD 10 == 9 PRINT
NEXT
PRINT "First" Task$(I%) " cyclop number > ";E% \
\ " is ";Exc%(I%) " at index ";Idx%(I%) "." '
NEXT
END
 
DEF FNIsPrime(n%) FOR I%=2 TO SQRn% IF n% MOD I% == 0 THEN =FALSE ELSE NEXT =TRUE</syntaxhighlight>
{{out}}
<pre>The first 50 cyclop numbers 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 cyclop number > 10000000 is 111101111 at index 538084.
 
The first 50 prime cyclop numbers 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 cyclop number > 10000000 is 111101129 at index 39320.
 
The first 50 blind prime cyclop numbers 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 cyclop number > 10000000 is 111101161 at index 11394.
 
The first 50 palindromic prime cyclop numbers 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 cyclop number > 10000000 is 114808411 at index 67.
</pre>
 
=={{header|C++}}==
<syntaxhighlight lang="c++">
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
 
template <class T>
void print(std::vector< T >, size_t);
 
bool isCyclopsNumber(int);
std::vector< int > firstCyclops(int);
bool isPrime(int);
std::vector< int > firstCyclopsPrimes(int);
int blindCyclops(int);
std::vector< int > firstBlindCyclopsPrimes(int);
bool isPalindrome(int);
std::vector< int > firstPalindromeCyclopsPrimes(int);
 
int main(void) {
auto first50 = firstCyclops(50);
 
std::cout << "First 50 cyclops numbers:" << std::endl;
print< int >(first50, 10);
auto prime50 = firstCyclopsPrimes(50);
 
std::cout << std::endl << "First 50 prime cyclops numbers:" << std::endl;
print< int >(prime50, 10);
auto blind50 = firstBlindCyclopsPrimes(50);
 
std::cout << std::endl << "First 50 blind prime cyclops numbers:" << std::endl;
print< int >(blind50, 10);
auto palindrome50 = firstPalindromeCyclopsPrimes(50);
 
std::cout << std::endl << "First 50 palindromic prime cyclops numbers:" << std::endl;
print< int >(palindrome50, 10);
return 0;
}
 
template <class T>
void print(std::vector< T > v, size_t nc) {
size_t col = 0;
for (auto e : v) {
std::cout << std::setw(8) << e << " ";
col++;
if (col == nc) {
std::cout << std::endl;
col = 0;
}
}
}
 
bool isCyclopsNumber(int n) {
if (n == 0) {
return true;
}
int m = n % 10;
int count = 0;
while (m != 0) {
count++;
n /= 10;
m = n % 10;
}
n /= 10;
m = n % 10;
while (m != 0) {
count--;
n /= 10;
m = n % 10;
}
return n == 0 && count == 0;
}
 
std::vector< int > firstCyclops(int n) {
std::vector< int > result;
int i = 0;
while (result.size() < n) {
if (isCyclopsNumber(i)) result.push_back(i);
i++;
}
return result;
}
 
bool isPrime(int n) {
if (n < 2) return false;
double s = std::sqrt(n);
for (int i = 2; i <= s; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
 
std::vector< int > firstCyclopsPrimes(int n) {
std::vector< int > result;
int i = 0;
while (result.size() < n) {
if (isCyclopsNumber(i) && isPrime(i)) result.push_back(i);
i++;
}
return result;
}
 
int blindCyclops(int n) {
int m = n % 10;
int k = 0;
while (m != 0) {
k = 10 * k + m;
n /= 10;
m = n % 10;
}
n /= 10;
while (k != 0) {
m = k % 10;
n = 10 * n + m;
k /= 10;
}
return n;
}
 
std::vector< int > firstBlindCyclopsPrimes(int n) {
std::vector< int > result;
int i = 0;
while (result.size() < n) {
if (isCyclopsNumber(i) && isPrime(i)) {
int j = blindCyclops(i);
if (isPrime(j)) result.push_back(i);
}
i++;
}
return result;
}
 
bool isPalindrome(int n) {
int k = 0;
int l = n;
while (l != 0) {
int m = l % 10;
k = 10 * k + m;
l /= 10;
}
return n == k;
}
 
std::vector< int > firstPalindromeCyclopsPrimes(int n) {
std::vector< int > result;
int i = 0;
while (result.size() < n) {
if (isCyclopsNumber(i) && isPrime(i) && isPalindrome(i)) result.push_back(i);
i++;
}
return result;
}
</syntaxhighlight>
{{out}}
<pre>
First 50 cyclops numbers:
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 50 prime cyclops numbers:
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 50 blind prime cyclops numbers:
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 50 palindromic prime cyclops numbers:
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
</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls,StrUtils,Math}}
Rather than iterating through all the numbers and picking out the various flavors of Cyclops numbers, this routine construct numbers with a minimum number of tests. The code is also modular so various subroutines reused for different types of cyclops.
 
<syntaxhighlight lang="Delphi">
var Base: integer; {Base value for iterating through cyclops numbers}
var OutStr: string; {Hold accumulating output data}
 
 
function NumberOfDigits(N: integer): integer;
{Find the number of digits in an integer}
begin
if N<1 then Result:=0
else Result:=Trunc(Log10(N))+1;
end;
 
 
procedure OutputNumber(Memo: TMemo; N: integer);
{Output number, grouping them 10 items per line}
begin
OutStr:=OutStr+Format('%8D',[N]);
if ((Length(OutStr) div 8) mod 10)=0 then
begin
Memo.Lines.Add(OutStr);
OutStr:='';
end;
end;
 
function IsPrime(N: integer): boolean;
{Optimised prime test - about 40% faster than the naive approach}
var I,Stop: integer;
begin
if (N = 2) or (N=3) then Result:=true
else if (n <= 1) or ((n mod 2) = 0) or ((n mod 3) = 0) then Result:= false
else
begin
I:=5;
Stop:=Trunc(sqrt(N));
Result:=False;
while I<=Stop do
begin
if ((N mod I) = 0) or ((N mod (i + 2)) = 0) then exit;
Inc(I,6);
end;
Result:=True;
end;
end;
 
function NonZeroIncrement(N: integer): integer;
{Find next number with no zero digits}
begin
repeat Inc(N)
until Pos('0',IntToStr(N))<1;
Result:=N;
end;
 
 
function GetNonZeroEvenDigits(N: integer): integer;
{Get next number with no zeros that has even number of digits}
begin
repeat N:=NonZeroIncrement(N)
until (NumberOfDigits(N) and 1)=0;
Result:=N;
end;
 
 
 
function InsertCenterZero(N: integer): integer;
{Insert a zero in the centers of a number}
{assumes the number is an even number digits long}
var S: string;
begin
S:=IntToStr(N);
Insert('0',S,(Length(S) div 2)+1);
Result:=StrToInt(S);
end;
 
 
function GetNextCyclops: integer;
{Get next cyclops number}
begin
Base:=GetNonZeroEvenDigits(Base);
Result:=InsertCenterZero(Base);
end;
 
 
 
function GetPalindromeCyclops: integer;
{Get next palindromic cyclops number}
var S1,S2: string;
begin
Base:=NonZeroIncrement(Base);
S1:=IntToStr(Base);
S2:=ReverseString(S1);
Result:=StrToInt(S1+'0'+S2);
end;
 
 
{--------------- Top level routines -------------------------------------------}
 
procedure GetCyclopsNumbers(Memo: TMemo);
{find first 50 Prime Cyclcops Numbers}
var I,C: integer;
var S: string;
begin
Memo.Lines.Add('First 50 Cyclops Numbers');
Base:=0;
OutputNumber(Memo,0);
for I:=1 to 50-1 do
begin
C:=GetNextCyclops;
OutputNumber(Memo,C);
end;
if OutStr<>'' then Memo.Lines.Add(OutStr);
end;
 
 
procedure GetPrimeCyclops(Memo: TMemo);
{find first 50 Prime Cyclcops Numbers}
var I,C: integer;
var S: string;
begin
Memo.Lines.Add('First 50 Prime Cyclops Numbers');
Base:=0;
for I:=1 to 50 do
begin
repeat C:=GetNextCyclops;
until IsPrime(C);
OutputNumber(Memo,C);
end;
if OutStr<>'' then Memo.Lines.Add(OutStr);
end;
 
 
procedure GetBlindPrimeCyclops(Memo: TMemo);
{find first 50 Blind Prime Cyclcops Numbers}
var I,C,CB: integer;
var S: string;
begin
Memo.Lines.Add('First 50 Blind Prime Cyclops Numbers');
Base:=0;
for I:=1 to 50 do
begin
repeat C:=GetNextCyclops;
until IsPrime(Base);
OutputNumber(Memo,C);
end;
if OutStr<>'' then Memo.Lines.Add(OutStr);
end;
 
 
procedure GetPalindromicPrimeCyclops(Memo: TMemo);
{find first 50 Palindromic Prime Cyclcops Numbers}
var I,C,CB: integer;
var S: string;
begin
Memo.Lines.Add('First 50 Palindromic Prime Cyclops Numbers');
Base:=0;
for I:=1 to 50 do
begin
repeat C:=GetPalindromeCyclops;
until IsPrime(C);
OutputNumber(Memo,C);
end;
if OutStr<>'' then Memo.Lines.Add(OutStr);
end;
 
 
 
 
procedure DisplayCyclopsNumbers(Memo: TMemo);
{Do full suite of Cyclops tasks}
begin
GetCyclopsNumbers(Memo);
GetPrimeCyclops(Memo);
GetBlindPrimeCyclops(Memo);
GetPalindromicPrimeCyclops(Memo);
end;
 
 
</syntaxhighlight>
{{out}}
<pre>
First 50 Cyclops Numbers
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 50 Prime Cyclops Numbers
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 50 Blind Prime Cyclops Numbers
101 103 107 109 203 209 301 307 401 403
407 503 509 601 607 701 703 709 803 809
907 11017 11023 11029 11051 11053 11063 11071 11081 11087
11093 12013 12017 12023 12029 12031 12037 12049 12059 12077
12079 12083 12089 12091 12097 13019 13021 13027 13061 13067
First 50 Palindromic Prime Cyclops Numbers
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
 
</pre>
 
=={{header|EasyLang}}==
{{trans|C++}}
<syntaxhighlight>
func is_cyclops n .
if n = 0
return 1
.
m = n mod 10
while m <> 0
count += 1
n = n div 10
m = n mod 10
.
n = n div 10
m = n mod 10
while m <> 0
count -= 1
n = n div 10
m = n mod 10
.
return if n = 0 and count = 0
.
fastfunc isprim num .
i = 2
while i <= sqrt num
if num mod i = 0
return 0
.
i += 1
.
return 1
.
func blind n .
m = n mod 10
while m <> 0
k = 10 * k + m
n = n div 10
m = n mod 10
.
n = n div 10
while k <> 0
m = k mod 10
n = 10 * n + m
k = k div 10
.
return n
.
func is_palindr n .
l = n
while l <> 0
m = l mod 10
k = 10 * k + m
l = l div 10
.
return if n = k
.
proc show . .
while cnt < 50
if is_cyclops i = 1
write i & " "
cnt += 1
.
i += 1
.
print ""
print ""
i = 2
cnt = 0
while cnt < 50
if is_cyclops i = 1 and isprim i = 1
write i & " "
cnt += 1
.
i += 1
.
print ""
print ""
i = 2
cnt = 0
while cnt < 50
if is_cyclops i = 1 and isprim i = 1
j = blind i
if isprim j = 1
write i & " "
cnt += 1
.
.
i += 1
.
print ""
print ""
i = 2
cnt = 0
while cnt < 50
if is_cyclops i = 1 and is_palindr i = 1 and isprim i = 1
write i & " "
cnt += 1
.
i += 1
.
.
show
</syntaxhighlight>
 
=={{header|Elixir}}==
<syntaxhighlight lang="elixir">
defmodule Rosetta do
def cy n do
require Integer
lc1=for cl <- 100..999, d=Integer.digits(cl),[q,y,z]=d,Integer.is_odd(length(d)) and y==0 and q>0 and z>0, do: cl
lc2=for cl <- 10000..99999, d=Integer.digits(cl),[q1,q2,y,z1,z2]=d,Integer.is_odd(length(d)) and y==0 and q1>0 and q2>0 and z1>0 and z2>0, do: cl
lc3=for cl <- 1000000..9999999, d=Integer.digits(cl),[q1,q2,q3,y,z1,z2,z3]=d,Integer.is_odd(length(d)) and y==0 and q1>0 and q2>0 and q3>0 and z1>0 and z2>0 and z3>0, do: cl
lc4=for cl <- 100000000..999999999, d=Integer.digits(cl),[q1,q2,q3,q4,y,z1,z2,z3,z4]=d,Integer.is_odd(length(d)) and y==0 and q1>0 and q2>0 and q3>0 and q4>0 and z1>0 and z2>0 and z3>0 and z4>0, do: cl
lc5=lc1++lc2++lc3++lc4
lc6=[0|lc5]
Enum.take(lc6,n)
end
"50 cyclops num"
iex(8)> cn=Rosetta.cy 50
[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]
def cyp cn,n do
cnp=for x <- cn,x>0,length(Enum.filter(1..x,fn y -> Integer.mod(x,y)==0 end))==2, do: x
Enum.take(cnp,n)
end
"50 cyclops primes"
iex(11)> Rosetta.cyp(Rosetta.cy(1000),50)
[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]
 
def cyz cn,n do
czn=for x <- cn, x>0,do: String.to_integer(String.replace(Integer.to_string(x),"0",""))
Enum.take(czn,n)
end
"50 blind cyclops prime"
iex(13)> Rosetta.cyp(Rosetta.cyz(Rosetta.cy(5000),1000),50)
[11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89,
97, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1213, 1217,
1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1319,
1321, 1327, 1361, 1367]
def cypa cn,n do
czp=for x <- cn,Integer.to_string(x)==String.reverse(Integer.to_string(x)), do: x
Enum.take(czp,n)
end
end
"50 palindrome prime cyclops"
iex(2)> Rosetta.cyp(Rosetta.cypa(Rosetta.cy(3000000),3000),50)
[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]
</syntaxhighlight>
 
=={{header|F_Sharp|F#}}==
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_functions Extensible Prime Generator (F#)]
===Cyclops function===
<lang<syntaxhighlight lang="fsharp">
// Cyclop numbers. Nigel Galloway: June 25th., 2021
let rec fG n g=seq{yield! g|>Seq.collect(fun i->g|>Seq.map(fun g->n*i+g)); yield! fG(n*10)(fN g)}
Line 369 ⟶ 1,316:
let primeCyclops,blindCyclops=cyclops|>Seq.filter isPrime,Seq.zip(fG 100 [1..9])(fG 10 [1..9])|>Seq.filter(fun(n,g)->isPrime n && isPrime g)|>Seq.map fst
let palindromicCyclops=let fN g=let rec fN g=[yield g%10; if g>9 then yield! fN(g/10)] in let n=fN g in n=List.rev n in primeCyclops|>Seq.filter fN
</syntaxhighlight>
</lang>
===The tasks===
; First 50 Cyclop numbers
<lang<syntaxhighlight lang="fsharp">
cyclops|>Seq.take 50|>Seq.iter(printf "%d "); printfn ""
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 380 ⟶ 1,327:
</pre>
; First 50 prime Cyclop numbers
<lang<syntaxhighlight lang="fsharp">
primeCyclops|>Seq.take 50|>Seq.iter(printf "%d "); printfn ""
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 388 ⟶ 1,335:
</pre>
; First 50 blind Cyclop numbers
<lang<syntaxhighlight lang="fsharp">
blindCyclops|>Seq.take 50|>Seq.iter(printf "%d "); printfn ""
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 396 ⟶ 1,343:
</pre>
; First 50 palindromic prime Cyclop numbers
<lang<syntaxhighlight lang="fsharp">
palindromicCyclops|>Seq.take 50|>Seq.iter(printf "%d "); printfn ""
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 404 ⟶ 1,351:
</pre>
; First Cyclop number > 10,000,000
<lang<syntaxhighlight lang="fsharp">
let n=cyclops|>Seq.findIndex(fun n->n>10000000) in printfn "First Cyclop number > 10,000,000 is %d at index %d" (Seq.item n (cyclops)) n
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 412 ⟶ 1,359:
</pre>
; First prime Cyclop number > 10,000,000
<lang<syntaxhighlight lang="fsharp">
let n=primeCyclops|>Seq.findIndex(fun n->n>10000000) in printfn "First prime Cyclop number > 10,000,000 is %d at index %d" (Seq.item n (primeCyclops)) n
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 420 ⟶ 1,367:
</pre>
; First blind Cyclop number > 10,000,000
<lang<syntaxhighlight lang="fsharp">
let n=blindCyclops|>Seq.findIndex(fun n->n>10000000) in printfn "First blind Cyclop number > 10,000,000 is %d at index %d" (Seq.item n (blindCyclops)) n
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 428 ⟶ 1,375:
</pre>
; First palindromic prime Cyclop number > 10,000,000
<lang<syntaxhighlight lang="fsharp">
let n=palindromicCyclops|>Seq.findIndex(fun n->n>10000000) in printfn "First palindromic prime Cyclop number > 10,000,000 is %d at index %d" (Seq.item n (palindromicCyclops)) n
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 454 ⟶ 1,401:
 
{{works with|Factor|0.99 2021-06-02}}
<lang<syntaxhighlight lang="factor">USING: accessors formatting grouping io kernel lists lists.lazy
math math.functions math.primes prettyprint sequences
tools.memory.private tools.time ;
Line 545 ⟶ 1,492:
! Extra stretch?
"One billionth cyclops number:" print
999,999,999 lcyclops lnth >integer commas print</langsyntaxhighlight>
{{out}}
<pre>
Line 591 ⟶ 1,538:
35,296,098,111
</pre>
 
=={{header|FreeBASIC}}==
{{trans|FutureBasic}}
<syntaxhighlight lang="vbnet">Dim Shared As Double t
Dim Shared As Uinteger n(16), clops(52), primes(52), blinds(52), pals(52)
Dim Shared As Uinteger num, iClop, iPrime, iBlind, iPal
Dim Shared As Uinteger first1, last1, midPt
midPt = 8
 
Function convertToNumber As Uinteger
Dim As Uinteger p10 = 1, nr = 0, c2 = last1
Do
nr += n(c2) * p10
If c2 = midPt Then p10 *= 100 Else p10 *= 10 'Add 0 if at midPoint
c2 -= 1
Loop Until c2 < first1
Return nr
End Function
 
Sub increment(dgt As Uinteger)
If n(dgt) < 9 Then n(dgt) += 1 : Exit Sub
n(dgt) = 1
If dgt > first1 Then increment(dgt - 1) : Exit Sub 'Carry
first1 -= 1 : last1 += 1
For dgt = first1 To last1 'New width: set all digits to 1
n(dgt) = 1
Next dgt
End Sub
 
Function isPrime(v As Uinteger) As Boolean
'Skip check for 2 and 3 because we're starting at 101
If v Mod 2 = 0 Then Return False
If v Mod 3 = 0 Then Return False
Dim As Uinteger f = 5
While f*f <= v
If v Mod f = 0 Then Return False
f += 2
If v Mod f = 0 Then Return False
f += 4
Wend
Return True
End Function
 
Function isBlind As Boolean
Dim As Uinteger temp = 0
Swap temp, midPt 'Keep fn convertToNumber from adding 0 at midPt
Dim As Boolean rslt = isPrime(convertToNumber())
Swap temp, midPt
Return rslt
End Function
 
Function isPalindrome As Boolean
Dim As Uinteger a = first1, b = last1
While b > a
If n(a) <> n(b) Then Return False
a += 1 : b -= 1
Wend
Return True
End Function
 
Sub print50(title As String, addr() As Uinteger)
Dim As Uinteger r = 0
Print : Print title
While r < 50
Print Using "#########"; addr(r);
r += 1 : If r Mod 10 = 0 Then Print
Wend
End Sub
 
Sub display
print50(" First 50 Cyclopean numbers:", clops())
print50(" First 50 Cyclopean primes:", primes())
print50(" First 50 blind Cyclopean primes:", blinds())
print50(" First 50 palindromic Cyclopean primes:", pals())
Print
Print Using " First Cyclopean number above 10,000,000 is ######### at index ######"; clops(50); clops(51)
Print Using " First Cyclopean prime above 10,000,000 is ######### at index ######"; primes(50); primes(51)
Print Using " First blind Cyclopean prime above 10,000,000 is ######### at index ######"; blinds(50); blinds(51)
Print Using " First palindromic Cyclopean prime above 10,000,000 is ######### at index ######"; pals(50); pals(51)
Print
Print Using " Compute time: ###.### sec"; t
End Sub
 
Sub cyclops
clops(0) = 0 : iClop = 1 : iPrime = 0 : iBlind = 0 : iPal = 0
first1 = midPt-1 : last1 = midPt : n(first1) = 1 : n(last1) = 1
' Record first 50 numbers in each category
While iPal < 50
num = convertToNumber()
If iClop < 50 Then clops(iClop) = num
iClop += 1
If isPrime(num) Then
If iPrime < 50 Then primes(iPrime) = num : iPrime += 1
If iBlind < 50 Andalso isBlind() Then blinds(iBlind) = num : iBlind += 1
If iPal < 50 Andalso isPalindrome() Then pals(iPal) = num : iPal += 1
End If
num += 1
increment(last1)
Wend
' Keep counting Cyclops numbers until 10,000,000
While convertToNumber() < 1e7
increment(last1) : iClop += 1
Wend
' Find next number in each category
clops(50) = convertToNumber() : clops(51) = iClop
iPrime = 1 : iBlind = 1 : iPal = 1
While (iPrime Or iBlind Or iPal)
num = convertToNumber()
iClop += 1
If isPrime(num) Then
If iPrime = 1 Then primes(50) = num : primes(51) = iClop : iPrime = 0
If iBlind = 1 Andalso isBlind() Then blinds(50) = num : blinds(51) = iClop : iBlind = 0
If iPal = 1 Andalso isPalindrome() Then pals(50) = num : pals(51) = iClop : iPal = 0
End If
increment(last1)
Wend
End Sub
 
t = Timer
cyclops()
t = Timer - t
display()
 
Sleep</syntaxhighlight>
{{out}}
<pre> First 50 Cyclopean numbers:
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 50 Cyclopean primes:
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 50 blind Cyclopean primes:
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 50 palindromic Cyclopean primes:
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 Cyclopean number above 10,000,000 is 111101111 at index 538084
First Cyclopean prime above 10,000,000 is 111101129 at index 538102
First blind Cyclopean prime above 10,000,000 is 111101161 at index 538130
First palindromic Cyclopean prime above 10,000,000 is 114808411 at index 766505
 
Compute time: 0.662 sec</pre>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
begin globals
CFTimeInterval t
long n(16), clops(52), primes(52), blinds(52), pals(52)
long num, iClop, iPrime, iBlind, iPal
short first1, last1, midPt
xref show(50) as long
midPt = 8
end globals
 
local fn convertToNumber as long
long p10 = 1, nr = 0
short c2 = last1
do
nr += n(c2) * p10
if c2 == midPt then p10 *= 100 else p10 *= 10 //Add 0 if at midPoint
c2--
until c2 < first1
end fn = nr
 
void local fn increment( dgt as short )
if n(dgt) < 9 then n(dgt)++ : exit fn
n(dgt) = 1
if dgt > first1 then fn increment( dgt - 1 ) : exit fn //Carry
first1-- : last1 ++
for dgt = first1 to last1 //New width: set all digits to 1
n(dgt) = 1
next
end fn
 
local fn isPrime( v as long ) as bool
//Skip check for 2 and 3 because we're starting at 101
if v mod 2 == 0 then exit fn = no
if v mod 3 == 0 then exit fn = no
long f = 5
while f*f <= v
if v mod f == 0 then exit fn = no
f += 2
if v mod f == 0 then exit fn = no
f += 4
wend
end fn = yes
 
local fn isBlind as bool
short temp = 0
swap temp, midPt //Keep fn convertToNumber from adding 0 at midPt
bool rslt = fn isPrime( fn convertToNumber )
swap temp, midPt
end fn = rslt
 
local fn isPalindrome as bool
short a = first1, b = last1
while b > a
if n(a) <> n(b) then exit fn = no
a++ : b--
wend
end fn = yes
 
void local fn print50( title as cfstringref, addr as ptr )
short r = 0
show = addr //Set array address to param
print : print title
while r < 50
printf @"%9ld\b",show(r)
r++ : if r mod 10 == 0 then print
wend
end fn
 
void local fn display
window 1, @"Cyclopean numbers", (0, 0, 680, 515 )
fn print50( @" First 50 Cyclopean numbers:", @clops( 0))
fn print50( @" First 50 Cyclopean primes:", @primes(0))
fn print50( @" First 50 blind Cyclopean primes:", @blinds(0))
fn print50( @" First 50 palindromic Cyclopean primes:",@pals( 0))
print
printf @" First Cyclopean number above 10,000,000 is %ld at index %ld", clops(50), clops(51)
printf @" First Cyclopean prime above 10,000,000 is %ld at index %ld", primes(50),primes(51)
printf @" First blind Cyclopean prime above 10,000,000 is %ld at index %ld", blinds(50),blinds(51)
printf @" First palindromic Cyclopean prime above 10,000,000 is %ld at index %ld", pals(50), pals(51)
print
printf @" Compute time: %.3f sec", t
end fn
 
void local fn cyclops
clops( 0 ) = 0 : iClop = 1 : iPrime = 0 : iBlind = 0 : iPal = 0
first1 = midPt-1 : last1 = midPt : n(first1) = 1 : n(last1) = 1
// Record first 50 numbers in each category
while ( iPal ) < 50
num = fn convertToNumber
if iClop < 50 then clops(iClop) = num
iClop++
if fn isPrime( num )
if iPrime < 50 then primes(iPrime) = num : iPrime++
if iBlind < 50 then if fn isBlind then blinds(iBlind) = num : iBlind++
if iPal < 50 then if fn isPalindrome then pals(iPal) = num : iPal++
end if
num++
fn increment( last1 )
wend
// Keep counting Cyclops numbers until 10,000,000
while fn convertToNumber < 10000000
fn increment( last1 ) : iClop++
wend
// Find next number in each category
clops(50) = fn convertToNumber : clops(51) = iClop
iPrime = 1 : iBlind = 1 : iPal = 1
while (iPrime or iBlind or iPal)
num = fn convertToNumber
iClop++
if fn isPrime( num )
if iPrime then primes(50) = num : primes(51) = iClop : iPrime--
if iBlind then if fn isBlind then blinds(50) = num : blinds(51) = iClop : iBlind--
if iPal then if fn isPalindrome then pals(50) = num : pals(51) = iClop : ipal--
end if
fn increment( last1 )
wend
end fn
 
t = fn CACurrentMediaTime
fn cyclops
t = fn CACurrentMediaTime - t
fn display
 
handleevents
</syntaxhighlight>
{{out}}
[[File:FB Cyclops output.png]]
 
 
=={{header|Go}}==
{{trans|Wren}}
{{libheader|Go-rcu}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 707 ⟶ 1,949:
ns, is = rcu.Commatize(n), rcu.Commatize(i)
fmt.Printf("\n\nFirst such number > 10 million is %s at zero-based index %s\n", ns, is)
}</langsyntaxhighlight>
 
{{out}}
Line 755 ⟶ 1,997:
=={{header|Haskell}}==
 
<lang<syntaxhighlight lang="haskell">import Control.Monad (replicateM)
import Data.Numbers.Primes (isPrime)
 
Line 761 ⟶ 2,003:
 
cyclops :: [Integer]
cyclops = [0 ..] >>= flankingDigitsgo
where
flankingDigitsgo 0 = [0]
flankingDigitsgo n =
(\s -> read s :: Integer)
fmap
<$> (\sfmap -((<>) read. s(<> ::"0")) Integer>>= (<*>))
( (fmap ((<>)replicateM .n (<>['1' "0")).. >>= (<*>)'9'])
(replicateM n ['1' .. '9'])
)
 
 
blindPrime :: Integer -> Bool
Line 777 ⟶ 2,016:
m = quot (length s) 2
in isPrime $
(\st -> read st :: Integer)
(take m s <> drop (succ m) s)
 
 
palindromic :: Integer -> Bool
palindromic = ((==) =<< reverse) . show
 
 
-------------------------- TESTS -------------------------
Line 806 ⟶ 2,043:
50
[show n | n <- cyclops, isPrime n, palindromic n]
]</langsyntaxhighlight>
<pre>First 50 Cyclops numbers – A134808:
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
Line 821 ⟶ 2,058:
=={{header|J}}==
 
<lang<syntaxhighlight Jlang="j">makecyclops =: 3 : 0
NB. y Number of digits (must be odd, greater than 2)
side =. nums #~ map =: -. '0' +./@:="1 nums =: ":"0 (0.1 * base) }. i. base =. 10 ^ <. -: y
, /:~ ". ,/ (side ,"1 0 '0') ,"1"2 1 side
)
Line 833 ⟶ 2,070:
((LF , 'First 50 blind prime Cyclops numbers:') , ": 5 10 $ (primes #~ (, ". '0' -.~"0 1 ": ,. primes) e. p: i.10000)) (1!:2) 2
(LF , 'First 50 palindromic prime Cyclops numbers:') , ": 5 10 $ primes #~ > (-: |.) &. > <@:":"1 ,. primes
) </langsyntaxhighlight>
 
<pre> go ''
Line 867 ⟶ 2,104:
=={{header|jq}}==
Note that the indices shown in the output are 0-based, as jq's index origin is 0.
<<syntaxhighlight lang="jq">
<lang jq>
## Generic helper functions
 
Line 936 ⟶ 2,173:
| (($l + 1) / 2 - 1) as $m
| $d[:$m] == ( $d[$m+1:] | reverse) ;
</syntaxhighlight>
</lang>
'''The tasks'''
<<syntaxhighlight lang="jq">
<lang jq>
def print5x10($width):
. as $a
Line 973 ⟶ 2,210:
main_task(50),
stretch_task(pow(10;7))
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,015 ⟶ 2,252:
=={{header|Julia}}==
Julia's indexes are 1 based, hence one greater than those of 0 based indices.
<lang<syntaxhighlight lang="julia">
print5x10(a, w = 8) = for i in 0:4, j in 1:10 print(lpad(a[10i + j], w), j == 10 ? "\n" : "") end
 
Line 1,082 ⟶ 2,319:
 
testcyclops()
</langsyntaxhighlight>{{out}}
<pre>
The first 50 cyclops numbers are:
Line 1,122 ⟶ 2,359:
 
=={{header|Ksh}}==
<lang<syntaxhighlight lang="ksh">
#!/bin/ksh
 
Line 1,232 ⟶ 2,469:
print "\nFirst $MAXN palindromic prime cyclops numbers:"
print ${palprcyarr[@]}
</syntaxhighlight>
</lang>
{{out}}<pre>
First 50 cyclops numbers:
Line 1,248 ⟶ 2,485:
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<lang<syntaxhighlight Mathematicalang="mathematica">a = Flatten[Table[FromDigits[{i, 0, j}], {i, 9}, {j, 9}], 1];
b = Flatten@Table[FromDigits@{i, j}, {i, 9}, {j, 9}];
c = Flatten@Table[FromDigits@{i, j, k}, {i, 9}, {j, 9}, {k, 9}];
Line 1,295 ⟶ 2,532:
TableHeadings -> {{"Prime", "Blind Prime",
"Palindromic Prime"}, {"Value",
"Index"}}], "First Cyclops numeber > 10,000,000", Top]</langsyntaxhighlight>
 
{{out}}<pre>
Line 1,334 ⟶ 2,571:
 
=={{header|Nim}}==
<lang<syntaxhighlight Nimlang="nim">import strutils, times
 
const Ranges = [0..0, 101..909, 11011..99099, 1110111..9990999, 111101111..999909999]
Line 1,442 ⟶ 2,679:
break
 
echo "\nExecution time: ", (cpuTime() - t0).formatFloat(ffDecimal, precision = 3), " seconds."</langsyntaxhighlight>
 
{{out}}
Line 1,488 ⟶ 2,725:
Added conversion of zero-based index to cyclops number<BR>
verified [https://oeis.org/A136098/b136098.txt List of palindromic prime cyclops numbers]
<lang<syntaxhighlight lang="pascal">program cyclops;
{$IFDEF FPC}
{$MODE DELPHI}
Line 1,986 ⟶ 3,223:
until cnt >1000*1000*1000*1000*1000;
end.
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,051 ⟶ 3,288:
{{trans|Raku}}
{{libheader|ntheory}}
<lang<syntaxhighlight lang="perl">use strict;
use warnings;
use feature 'say';
Line 2,086 ⟶ 3,323:
(sprintf "@{['%8d' x $upto]}", @values[0..$upto-1]) =~ s/(.{80})/$1\n/gr;
printf "First $text number > %s: %s at (zero based) index: %s\n\n", map { comma($_) } $over, $values[$i], $i;
}</langsyntaxhighlight>
{{out}}
<pre>First 50 cyclops numbers:
Line 2,127 ⟶ 3,364:
{{libheader|Phix/online}}
You can run this online [http://phix.x10.mx/p2js/cyclops.htm here] <small>(expect a blank screen for about 8s)</small>.
<!--<lang<syntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #004080;">atom</span> <span style="color: #000000;">t0</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">time</span><span style="color: #0000FF;">()</span>
Line 2,195 ⟶ 3,432:
<span style="color: #000000;">cyclops</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"palindromic prime "</span><span style="color: #0000FF;">)</span>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">elapsed</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">time</span><span style="color: #0000FF;">()-</span><span style="color: #000000;">t0</span><span style="color: #0000FF;">)</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 2,239 ⟶ 3,476:
=== billionth cyclops number ===
Finding the billionth number near-instantly. You can run this online [http://phix.x10.mx/p2js/bcyclops.htm here]
<!--<lang<syntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #004080;">atom</span> <span style="color: #000000;">t0</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">time</span><span style="color: #0000FF;">()</span>
Line 2,274 ⟶ 3,511:
<span style="color: #000000;">e</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">elapsed</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">time</span><span style="color: #0000FF;">()-</span><span style="color: #000000;">t0</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">fmt</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">half</span><span style="color: #0000FF;">[</span><span style="color: #000000;">left</span><span style="color: #0000FF;">]*</span><span style="color: #000000;">cpow</span><span style="color: #0000FF;">+</span><span style="color: #000000;">half</span><span style="color: #0000FF;">[</span><span style="color: #000000;">right</span><span style="color: #0000FF;">],</span><span style="color: #000000;">e</span><span style="color: #0000FF;">})</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
The 1,000,000,000th cyclops number is 35296098111 (0s)
</pre>
 
=={{header|Python}}==
<syntaxhighlight lang="python">from sympy import isprime
 
 
def print50(a, width=8):
for i, n in enumerate(a):
print(f'{n: {width},}', end='\n' if (i + 1) % 10 == 0 else '')
 
 
def generate_cyclops(maxdig=9):
yield 0
for d in range((maxdig + 1) // 2):
arr = [str(i) for i in range(10**d, 10**(d+1)) if not('0' in str(i))]
for left in arr:
for right in arr:
yield int(left + '0' + right)
 
 
def generate_prime_cyclops():
for c in generate_cyclops():
if isprime(c):
yield c
 
 
def generate_blind_prime_cyclops():
for c in generate_prime_cyclops():
cstr = str(c)
mid = len(cstr) // 2
if isprime(int(cstr[:mid] + cstr[mid+1:])):
yield c
 
 
def generate_palindromic_cyclops(maxdig=9):
for d in range((maxdig + 1) // 2):
arr = [str(i) for i in range(10**d, 10**(d+1)) if not('0' in str(i))]
for s in arr:
yield int(s + '0' + s[::-1])
 
 
def generate_palindromic_prime_cyclops():
for c in generate_palindromic_cyclops():
if isprime(c):
yield c
 
 
print('The first 50 cyclops numbers are:')
gen = generate_cyclops()
print50([next(gen) for _ in range(50)])
for i, c in enumerate(generate_cyclops()):
if c > 10000000:
print(
f'\nThe next cyclops number after 10,000,000 is {c} at position {i:,}.')
break
 
print('\nThe first 50 prime cyclops numbers are:')
gen = generate_prime_cyclops()
print50([next(gen) for _ in range(50)])
for i, c in enumerate(generate_prime_cyclops()):
if c > 10000000:
print(
f'\nThe next prime cyclops number after 10,000,000 is {c} at position {i:,}.')
break
 
print('\nThe first 50 blind prime cyclops numbers are:')
gen = generate_blind_prime_cyclops()
print50([next(gen) for _ in range(50)])
for i, c in enumerate(generate_blind_prime_cyclops()):
if c > 10000000:
print(
f'\nThe next blind prime cyclops number after 10,000,000 is {c} at position {i:,}.')
break
 
print('\nThe first 50 palindromic prime cyclops numbers are:')
gen = generate_palindromic_prime_cyclops()
print50([next(gen) for _ in range(50)], 11)
for i, c in enumerate(generate_palindromic_prime_cyclops()):
if c > 10000000:
print(
f'\nThe next palindromic prime cyclops number after 10,000,000 is {c} at position {i}.')
break
</syntaxhighlight>{{out}}
<pre>
The first 50 cyclops numbers 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
 
The next cyclops number after 10,000,000 is 111101111 at position 538,084.
 
The first 50 prime cyclops numbers are:
101 103 107 109 307 401 409 503 509 601
607 701 709 809 907 11,027 11,047 11,057 11,059 11,069
11,071 11,083 11,087 11,093 12,011 12,037 12,041 12,043 12,049 12,071
12,073 12,097 13,033 13,037 13,043 13,049 13,063 13,093 13,099 14,011
14,029 14,033 14,051 14,057 14,071 14,081 14,083 14,087 15,013 15,017
 
The next prime cyclops number after 10,000,000 is 111101129 at position 39,319.
 
The first 50 blind prime cyclops numbers are:
101 103 107 109 307 401 503 509 601 607
701 709 809 907 11,071 11,087 11,093 12,037 12,049 12,097
13,099 14,029 14,033 14,051 14,071 14,081 14,083 14,087 15,031 15,053
15,083 16,057 16,063 16,067 16,069 16,097 17,021 17,033 17,041 17,047
17,053 17,077 18,047 18,061 18,077 18,089 19,013 19,031 19,051 19,073
 
The next blind prime cyclops number after 10,000,000 is 111101161 at position 11,393.
 
The first 50 palindromic prime cyclops numbers are:
101 16,061 31,013 35,053 38,083 73,037 74,047 91,019 94,049 1,120,211
1,150,511 1,160,611 1,180,811 1,190,911 1,250,521 1,280,821 1,360,631 1,390,931 1,490,941 1,520,251
1,550,551 1,580,851 1,630,361 1,640,461 1,660,661 1,670,761 1,730,371 1,820,281 1,880,881 1,930,391
1,970,791 3,140,413 3,160,613 3,260,623 3,310,133 3,380,833 3,460,643 3,470,743 3,590,953 3,670,763
3,680,863 3,970,793 7,190,917 7,250,527 7,310,137 7,540,457 7,630,367 7,690,967 7,750,577 7,820,287
 
The next palindromic prime cyclops number after 10,000,000 is 114808411 at position 66.
</pre>
 
=={{header|Raku}}==
<<syntaxhighlight lang="raku" perl6line>use Lingua::EN::Numbers;
 
my @cyclops = 0, |flat lazy ^∞ .map: -> $exp {
Line 2,298 ⟶ 3,654:
"\n\nFirst {$type}cyclops number > 10,000,000: " ~ comma($iterator.first: * > 1e7 ) ~
" - at (zero based) index: " ~ comma $iterator.first: * > 1e7, :k;
}</langsyntaxhighlight>
 
{{out}}
Line 2,341 ⟶ 3,697:
 
=={{header|REXX}}==
<lang<syntaxhighlight lang="rexx">/*REXX pgm finds 1st N cyclops (Θ) #s, Θ primes, blind Θ primes, palindromic Θ primes*/
parse arg n cols . /*obtain optional argument from the CL.*/
if n=='' | n=="," then n= 50 /*Not specified? Then use the default.*/
Line 2,395 ⟶ 3,751:
end /*k*/ /* [↑] only process numbers ≤ √ J */
#= #+1; @.#= j; sq.#= j*j; !.j= 1 /*bump # Ps; assign next P; P sq; P# */
end /*j*/; return</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
Line 2,439 ⟶ 3,795:
 
=={{header|Ruby}}==
<lang<syntaxhighlight lang="ruby">require 'prime'
 
NONZEROS = %w(1 2 3 4 5 6 7 8 9)
Line 2,463 ⟶ 3,819:
puts "The first #{n} #{name} are: \n#{enum.take(n).to_a}\nFirst #{name} term > #{m}: #{cycl} at index: #{idx}.", ""
end
</syntaxhighlight>
</lang>
{{out}}
<pre>The first 50 cyclopes are:
Line 2,482 ⟶ 3,838:
</pre>
=={{header|Sidef}}==
<lang<syntaxhighlight lang="ruby">func cyclops_numbers(base = 10) {
Enumerator({|callback|
 
Line 2,565 ⟶ 3,921:
}).first(1)[0]
say "\nFirst #{text} term > #{min.commify}: #{arr[1].commify} at (zero based) index: #{arr[0].commify}\n"
}</langsyntaxhighlight>
{{out}}
<pre>
Line 2,606 ⟶ 3,962:
 
=={{header|Wren}}==
{{libheader|Wren-seqmath}}
{{libheader|Wren-fmt}}
{{libheader|Wren-str}}
<langsyntaxhighlight ecmascriptlang="wren">import "./math" for Int
import "./seqfmt" for LstFmt
import "./fmtstr" for FmtStr
import "/str" for Str
 
var findFirst = Fn.new { |list|
Line 2,636 ⟶ 3,991:
var candidates = cyclops[0...50]
var ni = findFirst.call(cyclops)
Fmt.tprint("$,6d", candidates, 10)
for (chunk in Lst.chunks(candidates, 10)) Fmt.print("$,6d", chunk)
Fmt.print("\nFirst such number > 10 million is $,d at zero-based index $,d", ni[0], ni[1])
 
Line 2,643 ⟶ 3,998:
candidates = primes.take(50).toList
ni = findFirst.call(primes)
Fmt.tprint("$,6d", candidates, 10)
for (chunk in Lst.chunks(candidates, 10)) Fmt.print("$,6d", chunk)
Fmt.print("\nFirst such number > 10 million is $,d at zero-based index $,d", ni[0], ni[1])
 
Line 2,659 ⟶ 4,014:
candidates = bpcyclops[0...50]
ni = findFirst.call(bpcyclops)
Fmt.tprint("$,6d", candidates, 10)
for (chunk in Lst.chunks(candidates, 10)) Fmt.print("$,6d", chunk)
Fmt.print("\nFirst such number > 10 million is $,d at zero-based index $,d", ni[0], ni[1])
 
Line 2,665 ⟶ 4,020:
candidates = ppcyclops[0...50]
ni = findFirst.call(ppcyclops)
Fmt.tprint("$,9d", candidates, 8)
for (chunk in Lst.chunks(candidates, 8)) Fmt.print("$,9d", chunk)
Fmt.print("\nFirst such number > 10 million is $,d at zero-based index $,d", ni[0], ni[1])</langsyntaxhighlight>
 
{{out}}
Line 2,713 ⟶ 4,068:
 
=={{header|XPL0}}==
<lang<syntaxhighlight XPL0lang="xpl0">func IsCyclops(N); \Return 'true' if N is a cyclops number
int N, I, J, K;
char A(9);
Line 2,828 ⟶ 4,183:
");
Common(3);
]</langsyntaxhighlight>
 
{{out}}
2,130

edits