Ascending primes: Difference between revisions
m
→{{header|Wren}}: Minor tidy
(→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="
import "./fmt" for Fmt
Line 2,377 ⟶ 2,376:
ascPrimes.addAll(higherPrimes)
System.print("There are %(ascPrimes.count) ascending primes, namely:")
{{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="
import "./math" for Int
import "./fmt" for Fmt
Line 2,423 ⟶ 2,421:
ascPrimes.sort()
System.print("There are %(ascPrimes.count) ascending primes, namely:")
{{out}}
|