Mersenne primes: Difference between revisions
Content added Content deleted
(→{{header|Wren}}: Replaced existing solution with one which uses BigInt.) |
|||
Line 1,400: | Line 1,400: | ||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
{{libheader|Wren-math}} |
{{libheader|Wren-math}} |
||
{{libheader|Wren-big}} |
|||
As far as exact integer arithmetic in Wren will allow us to go. |
|||
A bit slow so limited to first 14 Mersenne primes. |
|||
<lang ecmascript>import "/math" for Int |
<lang ecmascript>import "/math" for Int |
||
import "/big" for BigInt |
|||
var MAX = 14 |
|||
System.print("The |
System.print("The first %(MAX) Mersenne primes are:") |
||
for (i in 1..31) { |
|||
var count = 0 |
|||
var p = 2 |
|||
⚫ | |||
while (true) { |
|||
⚫ | |||
var m = (BigInt.one << p) - 1 |
|||
if (m.isProbablePrime(10)) { |
|||
System.print("2 ^ %(p) - 1") |
|||
count = count + 1 |
|||
if (count == MAX) break |
|||
} |
|||
while (true) { |
|||
⚫ | |||
⚫ | |||
} |
} |
||
}</lang> |
}</lang> |
||
Line 1,414: | Line 1,424: | ||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
The |
The first 14 Mersenne primes are: |
||
2 ^ 2 - 1 |
|||
2 ^ 3 - 1 |
|||
2 ^ 5 - 1 |
|||
2 ^ 7 - 1 |
|||
2 ^ 13 - 1 |
|||
2 ^ 17 - 1 |
|||
2 ^ 19 - 1 |
|||
2 ^ 31 - 1 |
|||
2 ^ 61 - 1 |
|||
2 ^ 89 - 1 |
|||
2 ^ 107 - 1 |
|||
2 ^ 127 - 1 |
|||
2 ^ 521 - 1 |
|||
2 ^ 607 - 1 |
|||
</pre> |
</pre> |
||