Data update

This commit is contained in:
Ingy döt Net 2023-12-16 21:33:55 -08:00
parent 35bcdeebf8
commit 74c69a0df6
2427 changed files with 31826 additions and 3468 deletions

View file

@ -0,0 +1,70 @@
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

View file

@ -0,0 +1,99 @@
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

View file

@ -0,0 +1,62 @@
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]

View file

@ -1,7 +1,6 @@
import "/math" for Int
import "/seq" for Lst
import "/fmt" for Fmt
import "/str" for Str
import "./math" for Int
import "./fmt" for Fmt
import "./str" for Str
var findFirst = Fn.new { |list|
var i = 0
@ -25,14 +24,14 @@ for (r in ranges) {
System.print("The first 50 cyclops numbers are:")
var candidates = cyclops[0...50]
var ni = findFirst.call(cyclops)
for (chunk in Lst.chunks(candidates, 10)) Fmt.print("$,6d", chunk)
Fmt.tprint("$,6d", candidates, 10)
Fmt.print("\nFirst such number > 10 million is $,d at zero-based index $,d", ni[0], ni[1])
System.print("\n\nThe first 50 prime cyclops numbers are:")
var primes = cyclops.where { |n| Int.isPrime(n) }
candidates = primes.take(50).toList
ni = findFirst.call(primes)
for (chunk in Lst.chunks(candidates, 10)) Fmt.print("$,6d", chunk)
Fmt.tprint("$,6d", candidates, 10)
Fmt.print("\nFirst such number > 10 million is $,d at zero-based index $,d", ni[0], ni[1])
System.print("\n\nThe first 50 blind prime cyclops numbers are:")
@ -48,11 +47,11 @@ for (p in primes) {
}
candidates = bpcyclops[0...50]
ni = findFirst.call(bpcyclops)
for (chunk in Lst.chunks(candidates, 10)) Fmt.print("$,6d", chunk)
Fmt.tprint("$,6d", candidates, 10)
Fmt.print("\nFirst such number > 10 million is $,d at zero-based index $,d", ni[0], ni[1])
System.print("\n\nThe first 50 palindromic prime cyclops numbers are:")
candidates = ppcyclops[0...50]
ni = findFirst.call(ppcyclops)
for (chunk in Lst.chunks(candidates, 8)) Fmt.print("$,9d", chunk)
Fmt.tprint("$,9d", candidates, 8)
Fmt.print("\nFirst such number > 10 million is $,d at zero-based index $,d", ni[0], ni[1])