Data update
This commit is contained in:
parent
ed705008a8
commit
0df55f9f24
2196 changed files with 32999 additions and 3075 deletions
50
Task/Ormiston-triples/EasyLang/ormiston-triples.easy
Normal file
50
Task/Ormiston-triples/EasyLang/ormiston-triples.easy
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
fastfunc isprim num .
|
||||
if num mod 3 = 0
|
||||
return 0
|
||||
.
|
||||
i = 5
|
||||
while i <= sqrt num
|
||||
if num mod i = 0
|
||||
return 0
|
||||
.
|
||||
i += 2
|
||||
if num mod i = 0
|
||||
return 0
|
||||
.
|
||||
i += 4
|
||||
.
|
||||
return 1
|
||||
.
|
||||
func nextprim n .
|
||||
repeat
|
||||
n += 2
|
||||
until isprim n = 1
|
||||
.
|
||||
return n
|
||||
.
|
||||
func digs n .
|
||||
while n > 0
|
||||
r += pow 10 (n mod 10)
|
||||
n = n div 10
|
||||
.
|
||||
return r
|
||||
.
|
||||
print "Smallest member of the first 25 Ormiston triples:"
|
||||
b = 2
|
||||
a = 3
|
||||
repeat
|
||||
c = b
|
||||
dc = db
|
||||
b = a
|
||||
db = da
|
||||
a = nextprim a
|
||||
until a > 1000000000
|
||||
da = digs a
|
||||
if da = db and da = dc
|
||||
cnt += 1
|
||||
if cnt <= 25
|
||||
write c & " "
|
||||
.
|
||||
.
|
||||
.
|
||||
print "Ormiston triples before 1 billion: " & cnt
|
||||
53
Task/Ormiston-triples/FreeBASIC/ormiston-triples.basic
Normal file
53
Task/Ormiston-triples/FreeBASIC/ormiston-triples.basic
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
Function GetSig(Byval N As Uinteger) As Uinteger 'Return signature of N
|
||||
'A "signature" is the count of each digit in N packed into a 32-bit word
|
||||
Dim As Uinteger Sig = 0
|
||||
Do While N > 0
|
||||
Sig += 1 Shl (N Mod 10)
|
||||
N \= 10
|
||||
Loop
|
||||
Return Sig
|
||||
End Function
|
||||
|
||||
Dim As Uinteger limite = 1e9
|
||||
Dim Shared As Boolean Sieve(limite)
|
||||
|
||||
Sub MakeSieve(Size As Uinteger) 'Make prime number sieve
|
||||
Dim As Uinteger Prime, i, K
|
||||
Size \= 2 'ignore even numbers
|
||||
For i = 0 To Size 'set Sieve flags all true
|
||||
Sieve(i) = True
|
||||
Next
|
||||
For i = 0 To Size
|
||||
If Sieve(i) Then 'found a prime, which is equal to
|
||||
Prime = i * 2 + 3 ' twice the index + 3
|
||||
K = i + Prime 'first multiple to strike off
|
||||
While K <= Size 'strike off all multiples
|
||||
Sieve(K) = False
|
||||
K += Prime
|
||||
Wend
|
||||
End If
|
||||
Next
|
||||
End Sub
|
||||
|
||||
MakeSieve(limite)
|
||||
Print "Smallest members of first 25 Ormiston triples:"
|
||||
Dim As Uinteger Cnt = 0, N0 = 0, N1 = 0, Sig0 = 0, Sig1 = 0, N = 3, Sig
|
||||
Dim As Double t0 = Timer
|
||||
Do
|
||||
If Sieve(N \ 2 - 1) Then ' is prime
|
||||
Sig = GetSig(N)
|
||||
If Sig = Sig0 Andalso Sig = Sig1 Then
|
||||
Cnt += 1
|
||||
If Cnt <= 25 Then
|
||||
Print Using "#,###,###,###"; N0;
|
||||
If Cnt Mod 5 = 0 Then Print
|
||||
End If
|
||||
End If
|
||||
Sig0 = Sig1: Sig1 = Sig
|
||||
N0 = N1: N1 = N
|
||||
End If
|
||||
If N >= limite Then Print Cnt; " Ormiston triples before one billion." : Exit Do
|
||||
N += 2
|
||||
Loop
|
||||
|
||||
Sleep
|
||||
Loading…
Add table
Add a link
Reference in a new issue