Ascending primes: Difference between revisions

m
(→‎J: simplify)
m (→‎{{header|Wren}}: Minor tidy)
Line 2,352:
===Version 1 (Sieve)===
Although they use a lot of memory, sieves usually produce good results in Wren and here we only need to sieve for primes up to 3456789 as there are just 9 possible candidates with 8 digits and 1 possible candidate with 9 digits which we can test for primality individually. The following runs in around 0.43 seconds.
<syntaxhighlight lang="ecmascriptwren">import "./math" for Int
import "./seq" for Lst
import "./fmt" for Fmt
 
Line 2,377 ⟶ 2,376:
ascPrimes.addAll(higherPrimes)
System.print("There are %(ascPrimes.count) ascending primes, namely:")
for (chunk in Lst.chunks(ascPrimes, 10)) Fmt.printtprint("$8d", chunkascPrimes, 10)</syntaxhighlight>
 
{{out}}
Line 2,398 ⟶ 2,397:
 
Much quicker than the 'sieve' approach at 0.013 seconds. I also tried using a powerset but that was slightly slower at 0.015 seconds.
<syntaxhighlight lang="ecmascriptwren">import "./set" for Set
import "./math" for Int
import "./seq" for Lst
import "./fmt" for Fmt
 
Line 2,423 ⟶ 2,421:
ascPrimes.sort()
System.print("There are %(ascPrimes.count) ascending primes, namely:")
for (chunk in Lst.chunks(ascPrimes, 10)) Fmt.printtprint("$8s8d", chunkascPrimes, 10)</syntaxhighlight>
 
{{out}}
9,483

edits