Data update

This commit is contained in:
Ingy döt Net 2024-10-16 18:07:41 -07:00
parent 81fd053722
commit 52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions

View file

@ -0,0 +1,132 @@
import java.util.ArrayList;
import java.util.List;
public final class CyclopsNumbers {
public static void main(String[] args) {
List<Integer> cyclops = new ArrayList<Integer>();
List<Integer> primeCyclops = new ArrayList<Integer>();
List<Integer> blindPrimeCyclops = new ArrayList<Integer>();
List<Integer> palindromicPrimeCyclops = new ArrayList<Integer>();
List<List<Integer>> ranges = List.of( List.of( 0, 0), List.of( 101, 909),
List.of( 11011, 99099 ), List.of( 1110111, 9990999 ), List.of( 111101111, 119101111 ) );
for ( List<Integer> range : ranges) {
for ( int i = range.getFirst(); i <= range.getLast(); i++ ) {
String value = String.valueOf(i);
if ( isCyclopsNumber(value) ) {
cyclops.addLast(i);
if ( isPrime(i) ) {
primeCyclops.addLast(i);
if ( isBlind(value) ) {
blindPrimeCyclops.addLast(i);
}
if ( isPalindromic(value) ) {
palindromicPrimeCyclops.addLast(i);
}
}
}
}
}
System.out.println("The first 50 Cyclops numbers:");
for ( int i = 0; i < 50; i++ ) {
System.out.print(String.format("%6s%s", cyclops.get(i), ( i % 10 == 9 ? "\n" : "" )));
}
System.out.println();
int firstIndex = firstIndex(cyclops);
System.out.println("The first cyclops number greater than ten million is "
+ cyclops.get(firstIndex) + " at zero based index " + firstIndex);
System.out.println();
System.out.println("The first 50 prime Cyclops numbers:");
for ( int i = 0; i < 50; i++ ) {
System.out.print(String.format("%7s%s", primeCyclops.get(i), ( i % 10 == 9 ? "\n" : "" )));
}
System.out.println();
firstIndex = firstIndex(primeCyclops);
System.out.println("The first prime cyclops number greater than ten million is "
+ primeCyclops.get(firstIndex) + " at zero based index " + firstIndex);
System.out.println();
System.out.println("The first 50 blind prime Cyclops numbers:");
for ( int i = 0; i < 50; i++ ) {
System.out.print(String.format("%7s%s", blindPrimeCyclops.get(i), ( i % 10 == 9 ? "\n" : "" )));
}
System.out.println();
firstIndex = firstIndex(blindPrimeCyclops);
System.out.println("The first blind prime cyclops number greater than ten million is "
+ blindPrimeCyclops.get(firstIndex) + " at zero based index " + firstIndex);
System.out.println();
System.out.println("The first 50 palindromic prime Cyclops numbers:");
for ( int i = 0; i < 50; i++ ) {
System.out.print(
String.format("%9s%s", palindromicPrimeCyclops.get(i), ( i % 10 == 9 ? "\n" : "" )));
}
System.out.println();
firstIndex = firstIndex(palindromicPrimeCyclops);
System.out.println("The first palindromic prime cyclops number greater than ten million is "
+ palindromicPrimeCyclops.get(firstIndex) + " at zero based index " + firstIndex);
System.out.println();
}
private static int firstIndex(List<Integer> numbers) {
int start = 0;
int end = numbers.size() - 1;
while ( start <= end ) {
final int mid = start + ( end - start ) / 2;
if ( numbers.get(mid) <= 10_000_000 ) {
start = mid + 1;
} else {
end = mid - 1;
}
}
return start;
}
private static boolean isCyclopsNumber(String text) {
return text.charAt(text.length() / 2) == '0' && text.indexOf('0') == text.lastIndexOf('0');
}
private static boolean isPalindromic(String text) {
for ( int i = 0; i < text.length() / 2; i++ ) {
if ( text.charAt(i) != text.charAt(text.length() - 1 - i) ) {
return false;
}
}
return true;
}
private static boolean isBlind(String text) {
final int middle = text.length() / 2;
final String withoutZero = text.substring(0, middle) + text.substring(middle + 1);
return isPrime(Integer.valueOf(withoutZero));
}
private static boolean isPrime(int number) {
if ( number < 2 ) {
return false;
}
if ( number % 2 == 0 ) {
return number == 2;
}
if ( number % 3 == 0 ) {
return number == 3;
}
int k = 5;
while ( k * k <= number ) {
if ( number % k == 0 ) {
return false;
}
k += 2;
if ( number % k == 0 ) {
return false;
}
k += 4;
}
return true;
}
}

View file

@ -0,0 +1,121 @@
include Settings
say version; say 'Cyclops numbers'; say
numeric digits 10; cycl. = 0
call GetCyclops 115e6
call Cyclops
call PrimeCyclops
call BlindPrimeCyclops
call PalPrimeCyclops
say Format(Time('e'),,3) 'seconds'
exit
GetCyclops:
procedure expose cycl.
arg x
m = 0; n = 1; cycl.cyclop.1 = 0
do f = 1
h = m+1; m = n
do j = 1 to 9
do i = h to m
a = cycl.cyclop.i
do k = 1 to 9
b = j||a||k
if b > x then
leave f
n = n+1; cycl.cyclop.n = b
end
end
end
end
cycl.0 = n
say n 'cyclops numbers generated <' x; say
return
Cyclops:
procedure expose cycl.
say 'First 50 cyclop numbers:'
do i = 1 to cycl.0
a = cycl.cyclop.i
if i <= 50 then do
call Charout ,Right(a,8)
if i//10 = 0 then
say
end
if a > 1e7 then do
say 'First such number > 1e7 is' a 'at index' i; say
leave i
end
end
return
PrimeCyclops:
procedure expose cycl.
say 'First 50 prime cyclop numbers:'
n = 0
do i = 2 to cycl.0
a = cycl.cyclop.i
if IsPrime(a) then do
n = n+1
if n <= 50 then do
call Charout ,Right(a,8)
if n//10 = 0 then
say
end
if a > 1e7 then do
say 'First such number > 1e7 is' a 'at index' n; say
leave i
end
end
end
return
BlindPrimeCyclops:
procedure expose cycl.
say 'First 50 blind prime cyclop numbers:'
n = 0
do i = 2 to cycl.0
a = cycl.cyclop.i
if IsPrime(a) then do
l = Length(a); m = l%2; b = Left(a,m)||Right(a,m)
if IsPrime(b) then do
n = n+1
if n <= 50 then do
call Charout ,Right(a,8)
if n//10 = 0 then
say
end
if a > 1e7 then do
say 'First such number > 1e7 is' a 'at index' n; say
leave i
end
end
end
end
return
PalPrimeCyclops:
procedure expose cycl.
say 'First 50 palindromic prime cyclop numbers:'
n = 0
do i = 2 to cycl.0
a = cycl.cyclop.i
if a = Reverse(a) then do
if IsPrime(a) then do
n = n+1
if n <= 50 then do
call Charout ,Right(a,8)
if n//10 = 0 then
say
end
if a > 1e7 then do
say 'First such number > 1e7 is' a 'at index' n; say
leave i
end
end
end
end
return
include Numbers
include Functions