Primorial numbers: Difference between revisions

Content deleted Content added
PureFox (talk | contribs)
→‎{{header|Wren}}: Added an embedded version using GMP.
PureFox (talk | contribs)
→‎Embedded: Now uses new Mpz.digitsinBase method.
Line 2,892: Line 2,892:
===Embedded===
===Embedded===
{{libheader|Wren-gmp}}
{{libheader|Wren-gmp}}
Far quicker, of course than the CLI version, completing in around 2.8 seconds.
Far quicker, of course than the CLI version, completing in around 2.0 seconds.

If we could use Mpz.sizeInBase(10) this would be twice as quick but unfortunately (for bases which aren't a power of two) it can return a figure which is one too big and does so here for primorial(10000) giving 45,338.
<lang ecmascript>import "./math" for Int
<lang ecmascript>import "./math" for Int
import "./gmp" for Mpz
import "./gmp" for Mpz
Line 2,908: Line 2,906:
System.print("\nThe following primorials have the lengths shown:")
System.print("\nThe following primorials have the lengths shown:")
for (i in [1e1, 1e2, 1e3, 1e4, 1e5, 1e6]) {
for (i in [1e1, 1e2, 1e3, 1e4, 1e5, 1e6]) {
Fmt.print("$7d: $d", i, z.primorial(primes[i]).toString.count)
Fmt.print("$7d: $d", i, z.primorial(primes[i]).digitsInBase(10))
}</lang>
}</lang>
{{out}}
{{out}}