Circular primes: Difference between revisions

m (→‎{{header|J}}: more concise definition for R (the rest is a bit verbose, but leaving it alone for now))
Line 1,036:
2 3 5 7 11 13 17 37 79 113 197 199 337 1193 3779 11939 19937 193939 199933
</pre>
=={{header|FutureBasic}}==
<syntaxhighlight lang="future basic"
 
begin globals
_last1 = 7
CFTimeInterval t
byte n(_last1 +1) //array of digits
uint64 list(20), p10 = 1
short count, digits, first1 = _last1
n(_last1) = 2 //First number to check
end globals
 
local fn convertToNumber as uint64
short i = first1
uint64 nr = n(i)
while i < _last1
i++ : nr = nr * 10 + n(i)
wend
end fn = nr
 
void local fn increment( dgt as short )
select n(dgt)
case 1, 7, 5 : n(dgt) += 2
case 3 : if digits then n(dgt) = 7 else n(dgt) = 5
case 9 : n(dgt) = 1
if dgt == first1 then first1-- : digits++ : p10 *= 10
fn increment( dgt -1 )
case else : n(dgt)++
end select
end fn
 
local fn isPrime( v as uint64 ) as bool
if v < 4 then exit fn = yes
if v mod 3 == 0 then exit fn = no
uint64 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
 
void local fn circularPrimes
uint64 num, nr
short r
while ( count < 19 )
num = fn convertToNumber
if fn isPrime( num )
nr = num
for r = 1 to digits
nr = 10 * ( nr mod p10 ) + ( nr / p10 ) //Rotate
if nr < num then break //Rotation of lower number
if fn isPrime( nr ) == no then break //Not prime
next
if r > digits then list( count ) = num : count++//:print num:stop
end if
fn increment( _last1 )
wend
end fn
 
window 1, @"Circular Primes in FutureBasic", (0, 0, 280, 320 )
t = fn CACurrentMediaTime
fn circularPrimes
t = fn CACurrentMediaTime - t
for count = 0 to 18
printf @"%22u",list(count)
next
printf @"\n Compute time: %.3f ms", t * 1000
handleevents
 
</syntaxhighlight>
{{out}}
[[File:Screenshot of Circular Primes in FutureBasic.png]]
 
=={{header|Go}}==
{{libheader|GMP(Go wrapper)}}
Line 1,179 ⟶ 1,254:
R(49081) : true
</pre>
 
=={{header|Haskell}}==
Uses arithmoi Library: http://hackage.haskell.org/package/arithmoi-0.10.0.0
68

edits