Ormiston pairs: Difference between revisions

Ormiston pairs in FreeBASIC
m (→‎{{header|Free Pascal}}: changed to segmented prime sieve. Generating and extract primes takes the most time.)
(Ormiston pairs in FreeBASIC)
Line 239:
382 Ormiston pairs less than a million.
</pre>
 
=={{header|FreeBASIC}}==
{{trans|XPL0}}
<syntaxhighlight lang="vb">#include "isprime.bas"
 
Function GetSig(Byval N As Integer) As Integer
Dim As Integer Sig = 0
Do While N > 0
Sig += 1 Shl (N Mod 10)
N \= 10
Loop
Return Sig
End Function
 
Dim As Integer Cnt = 0, N0 = 0, Sig0 = 0, N = 3, Sig
Do
If isPrime(N) Then
Sig = GetSig(N)
If Sig = Sig0 Then
Cnt += 1
If Cnt <= 30 Then
Print Using "##### #####"; N0; N;
If Cnt Mod 3 = 0 Then Print Else Print " ";
End If
End If
Sig0 = Sig
N0 = N
End If
If N = 1e5 -1 Then Print !"\nOrmiston pairs up to one hundred thousand: "; Cnt
If N = 1e6 -1 Then Print "Ormiston pairs up to one million: "; Cnt
If N = 1e7 -1 Then Print "Ormiston pairs up to ten million: "; Cnt: Exit Do
N += 2
Loop
 
Sleep</syntaxhighlight>
{{out}}
<pre> 1913 1931 18379 18397 19013 19031
25013 25031 34613 34631 35617 35671
35879 35897 36979 36997 37379 37397
37813 37831 40013 40031 40213 40231
40639 40693 45613 45631 48091 48109
49279 49297 51613 51631 55313 55331
56179 56197 56713 56731 58613 58631
63079 63097 63179 63197 64091 64109
65479 65497 66413 66431 74779 74797
75913 75931 76213 76231 76579 76597
 
Ormiston pairs up to one hundred thousand: 40
Ormiston pairs up to one million: 382
Ormiston pairs up to ten million: 3722</pre>
 
=={{header|Go}}==
2,130

edits