Circular primes: Difference between revisions

→‎{{header|Wren}}: Updated to use BigInt for second part.
(refactored the code to reduce stack juggling in circular?)
(→‎{{header|Wren}}: Updated to use BigInt for second part.)
Line 2,404:
{{trans|Go}}
{{libheader|Wren-math}}
{{libheader|Wren-big}}
Just the first part as no 'big integer' support.
Second part is very slow - over 37 minutes to find all four.
<lang ecmascript>import "/math" for Int
import "/big" for BigInt
var circs = []
Line 2,427 ⟶ 2,429:
return true
}
 
var repunit = Fn.new { |n| BigInt.new("1" * n) }
System.print("The first 19 circular primes are:")
Line 2,454 ⟶ 2,458:
}
}
System.print(circs)</lang>
 
System.print("\nThe next 4 circular primes, in repunit format, are:")
count = 0
var rus = []
var primes = Int.primeSieve(10000)
for (p in primes[3..-1]) {
if (repunit.call(p).isProbablePrime(1)) {
rus.add("R(%(p))")
count = count + 1
if (count == 3) break
}
}
System.print(rus)</lang>
 
{{out}}
Line 2,460 ⟶ 2,477:
The first 19 circular primes are:
[2, 3, 5, 7, 11, 13, 17, 37, 79, 113, 197, 199, 337, 1193, 3779, 11939, 19937, 193939, 199933]
 
The next 4 circular primes, in repunit format, are:
[R(19), R(23), R(317), R(1031)]
</pre>
 
=={{header|Zig}}==
As of now (Zig release 0.8.1), Zig has large integer support, but there is not yet a prime test in the standard library. Therefore, we only find the circular primes < 1e6. As with the Prolog version, we only check numbers composed of 1, 3, 7, or 9.
9,476

edits