Ascending primes: Difference between revisions

m
syntax highlighting fixup automation
(implementation in Forth)
m (syntax highlighting fixup automation)
Line 25:
{{libheader|ALGOL 68-primes}}
{{libheader|ALGOL 68-rows}}
<langsyntaxhighlight lang=algol68>BEGIN # find all primes with strictly increasing digits #
PR read "primes.incl.a68" PR # include prime utilities #
PR read "rows.incl.a68" PR # include array utilities #
Line 68:
IF i MOD 10 = 0 THEN print( ( newline ) ) FI
OD
END</langsyntaxhighlight>
{{out}}
<pre>
Line 84:
=={{header|Arturo}}==
 
<langsyntaxhighlight lang=rebol>ascending?: function [x][
initial: digits x
and? [equal? sort initial initial][equal? size initial size unique initial]
Line 98:
loop split.every:10 ascendingNums 'nums [
print map nums 'num -> pad to :string num 10
]</langsyntaxhighlight>
 
{{out}}
Line 114:
 
=={{header|AWK}}==
<langsyntaxhighlight lang=AWK>
# syntax: GAWK -f ASCENDING_PRIMES.AWK
BEGIN {
Line 151:
return(1)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 170:
=={{header|C}}==
{{trans|Fortran}}
<langsyntaxhighlight lang=C>/*
* Ascending primes
*
Line 261:
return EXIT_SUCCESS;
}</langsyntaxhighlight>
{{output}}
<pre>2 3 5 7 13 17 19 23 29 37 47 59 67 79 89 127 137 139 149 157 167 179 239 257 269 347 349 359 367 379 389 457 467 479 569 1237 1249 1259 1279 1289 1367 1459 1489 1567 1579 1789 2347 2357 2389 2459 2467 2579 2689 2789 3457 3467 3469 4567 4679 4789 5689 12347 12379 12457 12479 12569 12589 12689 13457 13469 13567 13679 13789 15679 23459 23567 23689 23789 25679 34589 34679 123457 123479 124567 124679 125789 134789 145679 234589 235679 235789 245789 345679 345689 1234789 1235789 1245689 1456789 12356789 23456789 </pre>
Line 267:
=={{header|C++}}==
{{trans|C}}
<langsyntaxhighlight lang=Cpp>/*
* Ascending primes
*
Line 352:
 
return EXIT_SUCCESS;
}</langsyntaxhighlight>
{{Output}}
<pre>2 3 5 7 13 17 19 23 29 37 47 59 67 79 89 127 137 139 149 157 167 179 239 257 269 347 349 359 367 379 389 457 467 479 569 1237 1249 1259 1279 1289 1367 1459 1489 1567 1579 1789 2347 2357 2389 2459 2467 2579 2689 2789 3457 3467 3469 4567 4679 4789 5689 12347 12379 12457 12479 12569 12589 12689 13457 13469 13567 13679 13789 15679 23459 23567 23689 23789 25679 34589 34679 123457 123479 124567 124679 125789 134789 145679 234589 235679 235789 245789 345679 345689 1234789 1235789 1245689 1456789 12356789 23456789 </pre>
Line 358:
=={{header|C#}}==
{{trans|PHP}}
<langsyntaxhighlight lang=Csharp>using System;
using System.Collections.Generic;
 
Line 401:
}
}
}</langsyntaxhighlight>
{{Output}}
<pre>2 3 5 7 13 17 19 23 29 37 47 59 67 79 89 127 137 139 149 157 167 179 239 257 269 347 349 359 367 379 389 457 467 479 569 1237 1249 1259 1279 1289 1367 1459 1489 1567 1579 1789 2347 2357 2389 2459 2467 2579 2689 2789 3457 3467 3469 4567 4679 4789 5689 12347 12379 12457 12479 12569 12589 12689 13457 13469 13567 13679 13789 15679 23459 23567 23689 23789 25679 34589 34679 123457 123479 124567 124679 125789 134789 145679 234589 235679 235789 245789 345679 345689 1234789 1235789 1245689 1456789 12356789 23456789</pre>
Line 407:
=={{header|F_Sharp|F#}}==
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_functions Extensible Prime Generator (F#)]
<langsyntaxhighlight lang=fsharp>
// Ascending primes. Nigel Galloway: April 19th., 2022
[2;3;5;7]::List.unfold(fun(n,i)->match n with []->None |_->let n=n|>List.map(fun(n,g)->[for n in n.. -1..1->(n-1,i*n+g)])|>List.concat in Some(n|>List.choose(fun(_,n)->if isPrime n then Some n else None),(n|>List.filter(fst>>(<)0),i*10)))([(2,3);(6,7);(8,9)],10)
|>List.concat|>List.sort|>List.iter(printf "%d "); printfn ""
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 419:
The approach taken is to check the members of the powerset of [1..9] (of which there are only 512 if you include the empty set) for primality.
{{works with|Factor|0.99 2021-06-02}}
<langsyntaxhighlight lang=factor>USING: grouping math math.combinatorics math.functions
math.primes math.ranges prettyprint sequences sequences.extras ;
 
9 [1,b] all-subsets [ reverse 0 [ 10^ * + ] reduce-index ]
[ prime? ] map-filter 10 group simple-table.</langsyntaxhighlight>
{{out}}
<pre>
Line 442:
{{works with|gforth|0.7.3}}
<br>
<langsyntaxhighlight lang=forth>#! /usr/bin/gforth
 
\ Ascending primes
Line 487:
 
ascending-primes bye
</syntaxhighlight>
</lang>
 
{{out}}
Line 496:
 
=={{header|Fortran}}==
<langsyntaxhighlight lang=Fortran>! Ascending primes
!
! Generate and show all primes with strictly ascending decimal digits.
Line 582:
end if
isprime = .TRUE.
end function</langsyntaxhighlight>
{{Output}}
The estimated execution time is 1.5 milliseconds on the same hardware on which the Java program was run. It should be remembered that modern CPUs do not have a constant clock speed and additionally the measured times depend on the system load with other tasks. Nevertheless, the Fortran program seems to be 4 times faster than the Java program.
Line 608:
{{libheader|Go-rcu}}
Using a generator.
<langsyntaxhighlight lang=go>package main
 
import (
Line 650:
}
}
}</langsyntaxhighlight>
 
{{out}}
Line 673:
[https://jsoftware.github.io/j-playground/bin/html/emj.html#code=%20%20%20extend%3D%3A%20%7B%7B%20y%3B(1%2Beach%20i._1%2B%7B.y)%2CL%3A0%20y%20%7D%7D%0D%0A%20%20%2010%2010%24(%23~%201%20p%3A%20%5D)10%23.%26%3E(%5B%3A~.%40%3Bextend%20each)%5E%3A%23%20%3E%3Ai.9 Live link].
 
<langsyntaxhighlight lang=J> extend=: {{ y;(1+each i._1+{.y),L:0 y }}
$(#~ 1 p: ])10#.&>([:~.@;extend each)^:# >:i.9
100
Line 689:
timex'(#~ 1 p: ])10#.&>([:~.@;extend each)^:# >:i.9' NB. seconds (take with grain of salt)
0.003818
</syntaxhighlight>
</lang>
 
cpu here was a 1.2ghz i3-1005g1
Line 695:
=={{header|Java}}==
{{trans|C++}}
<langsyntaxhighlight lang=Java>/*
* Ascending primes
*
Line 771:
return true;
}
}</langsyntaxhighlight>
{{Output}}
<pre>[2, 3, 5, 7, 13, 17, 19, 23, 29, 37, 47, 59, 67, 79, 89, 127, 137, 139, 149, 157, 167, 179, 239, 257, 269, 347, 349, 359, 367, 379, 389, 457, 467, 479, 569, 1237, 1249, 1259, 1279, 1289, 1367, 1459, 1489, 1567, 1579, 1789, 2347, 2357, 2389, 2459, 2467, 2579, 2689, 2789, 3457, 3467, 3469, 4567, 4679, 4789, 5689, 12347, 12379, 12457, 12479, 12569, 12589, 12689, 13457, 13469, 13567, 13679, 13789, 15679, 23459, 23567, 23689, 23789, 25679, 34589, 34679, 123457, 123479, 124567, 124679, 125789, 134789, 145679, 234589, 235679, 235789, 245789, 345679, 345689, 1234789, 1235789, 1245689, 1456789, 12356789, 23456789]
Line 778:
=={{header|JavaScript}}==
{{trans|Java}}
<langsyntaxhighlight lang=javascript><!DOCTYPE html>
<html>
<body>
Line 821:
 
</body>
</html></langsyntaxhighlight>
{{Output}}
<pre>2,3,5,7,13,17,19,23,29,37,47,59,67,79,89,127,137,139,149,157,167,179,239,257,269,347,349,359,367,379,389,457,467,479,569,1237,1249,1259,1279,1289,1367,1459,1489,1567,1579,1789,2347,2357,2389,2459,2467,2579,2689,2789,3457,3467,3469,4567,4679,4789,5689,12347,12379,12457,12479,12569,12589,12689,13457,13469,13567,13679,13789,15679,23459,23567,23689,23789,25679,34589,34679,123457,123479,124567,124679,125789,134789,145679,234589,235679,235789,245789,345679,345689,1234789,1235789,1245689,1456789,12356789,23456789</pre>
Line 831:
See [[Erdős-primes#jq]] for a suitable definition of `is_prime` as used here.
 
<syntaxhighlight lang=jq>
<lang jq>
# Output: the stream of ascending primes, in order
def ascendingPrimes:
Line 855:
( _nwise(10) | map(lpad(10)) | join(" ") );
 
task</langsyntaxhighlight>
{{out}}
<pre>
Line 873:
 
=={{header|Julia}}==
<langsyntaxhighlight lang=julia>using Combinatorics
using Primes
 
Line 885:
@time ascendingprimes()
 
</langsyntaxhighlight>{{out}}
<pre>
2 3 5 7 13 17 19 23 29 37
Line 903:
=={{header|Lua}}==
Exactly 511 calls to <code>is_prime</code> required.
<langsyntaxhighlight lang=Lua>local function is_prime(n)
if n < 2 then return false end
if n % 2 == 0 then return n==2 end
Line 926:
end
 
print(table.concat(ascending_primes(), ", "))</langsyntaxhighlight>
{{out}}
<pre>2, 3, 5, 7, 13, 17, 19, 23, 29, 37, 47, 59, 67, 79, 89, 127, 137, 139, 149, 157, 167, 179, 239, 257, 269, 347, 349, 359, 367, 379, 389, 457, 467, 479, 569, 1237, 1249, 1259, 1279, 1289, 1367, 1459, 1489, 1567, 1579, 1789, 2347, 2357, 2389, 2459, 2467, 2579, 2689, 2789, 3457, 3467, 3469, 4567, 4679, 4789, 5689, 12347, 12379, 12457, 12479, 12569, 12589, 12689, 13457, 13469, 13567, 13679, 13789, 15679, 23459, 23567, 23689, 23789, 25679, 34589, 34679, 123457, 123479, 124567, 124679, 125789, 134789, 145679, 234589, 235679, 235789, 245789, 345679, 345689, 1234789, 1235789, 1245689, 1456789, 12356789, 23456789</pre>
Line 932:
=={{header|Matlab}}==
{{trans|Java}}
<langsyntaxhighlight lang=matlab>queue = 1:9;
 
j = 1;
Line 945:
end
 
queue(isprime(queue))</langsyntaxhighlight>
 
{{Output}}
Line 1,003:
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight lang=Mathematica>ps=Sort@Select[FromDigits /@ Subsets[Range@9, {1, \[Infinity]}], PrimeQ];
Multicolumn[ps, {Automatic, 6}, Appearance -> "Horizontal"]</langsyntaxhighlight>
{{out}}
<pre>2 3 5 7 13 17 19 23
Line 1,022:
=={{header|Pascal}}==
{{trans|JavaScript}}
<langsyntaxhighlight lang=pascal>{$mode Delphi}
 
{ Note that for the program to work properly,
Line 1,096:
writeln()
 
end.</langsyntaxhighlight>
{{Output}}
<pre>2 3 5 7 13 17 19 23 29 37 47 59 67 79 89 127 137 139 149 157 167 179 239 257 269 347 349 359 367 379 389 457 467 479 569 1237 1249 1259 1279 1289 1367 1459 1489 1567 1579 1789 2347 2357 2389 2459 2467 2579 2689 2789 3457 3467 3469 4567 4679 4789 5689 12347 12379 12457 12479 12569 12589 12689 13457 13469 13567 13679 13789 15679 23459 23567 23689 23789 25679 34589 34679 123457 123479 124567 124679 125789 134789 145679 234589 235679 235789 245789 345679 345689 1234789 1235789 1245689 1456789 12356789 23456789 </pre>
 
=={{header|Perl}}==
<langsyntaxhighlight lang=perl>#!/usr/bin/perl
 
use strict; # https://rosettacode.org/wiki/Ascending_primes
Line 1,109:
print join('', map { sprintf "%10d", $_ } sort { $a <=> $b }
grep /./ && is_prime($_),
glob join '', map "{$_,}", 1 .. 9) =~ s/.{50}\K/\n/gr;</langsyntaxhighlight>
{{out}}
<pre>
Line 1,135:
 
=={{header|Phix}}==
<!--<langsyntaxhighlight lang=Phix>(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">ascending_primes</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">atom</span> <span style="color: #000000;">p</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span><span style="color: #0000FF;">)</span>
Line 1,148:
<span style="color: #004080;">sequence</span> <span style="color: #000000;">r</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">,{{</span><span style="color: #008000;">"%8d"</span><span style="color: #0000FF;">},</span><span style="color: #7060A8;">sort</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ascending_primes</span><span style="color: #0000FF;">({</span><span style="color: #000000;">2</span><span style="color: #0000FF;">}))})</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"There are %,d ascending primes:\n%s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">r</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #000000;">r</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" "</span><span style="color: #0000FF;">)})</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,165:
===powerset===
Using a powerset, the basic idea of which was taken from the Factor entry above, here incrementally built, does not need either recursion or a sort, same output
<!--<langsyntaxhighlight lang=Phix>(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">ascending_primes</span><span style="color: #0000FF;">()</span>
Line 1,184:
<span style="color: #004080;">sequence</span> <span style="color: #000000;">r</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">,{{</span><span style="color: #008000;">"%8d"</span><span style="color: #0000FF;">},</span><span style="color: #000000;">ascending_primes</span><span style="color: #0000FF;">()})</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"There are %,d ascending primes:\n%s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">r</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #000000;">r</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" "</span><span style="color: #0000FF;">)})</span>
<!--</langsyntaxhighlight>-->
By way of explanation, specifically "no sort rqd", if you <code>pp(shorten(powerset,"entries",3))</code> at the end of each iteration then you get:
<pre>
Line 1,201:
=={{header|PHP}}==
{{trans|JavaScript}}
<langsyntaxhighlight lang=php><?php
 
function isPrime($n)
Line 1,236:
 
foreach($primes as $p)
echo "$p ";</langsyntaxhighlight>
{{Output}}
<pre>2 3 5 7 13 17 19 23 29 37 47 59 67 79 89 127 137 139 149 157 167 179 239 257 269 347 349 359 367 379 389 457 467 479 569 1237 1249 1259 1279 1289 1367 1459 1489 1567 1579 1789 2347 2357 2389 2459 2467 2579 2689 2789 3457 3467 3469 4567 4679 4789 5689 12347 12379 12457 12479 12569 12589 12689 13457 13469 13567 13679 13789 15679 23459 23567 23689 23789 25679 34589 34679 123457 123479 124567 124679 125789 134789 145679 234589 235679 235789 245789 345679 345689 1234789 1235789 1245689 1456789 12356789 23456789 </pre>
 
=={{header|Picat}}==
<langsyntaxhighlight lang=Picat>import util.
 
main =>
Line 1,249:
end,
nl,
println(len=DP.len)</langsyntaxhighlight>
 
{{out}}
Line 1,266:
 
=={{header|PicoLisp}}==
<langsyntaxhighlight lang=PicoLisp>(de prime? (N)
(or
(= N 2)
Line 1,288:
(let Fmt (need 10 10)
(while (cut 10 'Lst)
(apply tab @ Fmt) ) ) )</langsyntaxhighlight>
{{out}}
<pre>
Line 1,306:
===Recursive solution, with a number generator and sorting of results.===
 
<langsyntaxhighlight lang=Python>from sympy import isprime
 
def ascending(x=0):
Line 1,313:
yield(y)
 
print(sorted(x for x in ascending() if isprime(x)))</langsyntaxhighlight>
{{out}}
<pre>[2, 3, 5, 7, 13, 17, 19, 23, 29, 37, 47, 59, 67, 79, 89, 127, 137, 139, 149, 157, 167, 179, 239, 257, 269, 347, 349, 359, 367, 379, 389, 457, 467, 479, 569, 1237, 1249, 1259, 1279, 1289, 1367, 1459, 1489, 1567, 1579, 1789, 2347, 2357, 2389, 2459, 2467, 2579, 2689, 2789, 3457, 3467, 3469, 4567, 4679, 4789, 5689, 12347, 12379, 12457, 12479, 12569, 12589, 12689, 13457, 13469, 13567, 13679, 13789, 15679, 23459, 23567, 23689, 23789, 25679, 34589, 34679, 123457, 123479, 124567, 124679, 125789, 134789, 145679, 234589, 235679, 235789, 245789, 345679, 345689, 1234789, 1235789, 1245689, 1456789, 12356789, 23456789]</pre>
Line 1,319:
===Queue-based solution that does not need sorting.===
{{trans|Pascal}}
<langsyntaxhighlight lang=python>def isprime(n):
if n == 2: return True
if n == 1 or n % 2 == 0: return False
Line 1,336:
queue.extend(n * 10 + k for k in range(n % 10 + 1, 10))
 
print(primes)</langsyntaxhighlight>
{{Output}}
<pre>[2, 3, 5, 7, 13, 17, 19, 23, 29, 37, 47, 59, 67, 79, 89, 127, 137, 139, 149, 157, 167, 179, 239, 257, 269, 347, 349, 359, 367, 379, 389, 457, 467, 479, 569, 1237, 1249, 1259, 1279, 1289, 1367, 1459, 1489, 1567, 1579, 1789, 2347, 2357, 2389, 2459, 2467, 2579, 2689, 2789, 3457, 3467, 3469, 4567, 4679, 4789, 5689, 12347, 12379, 12457, 12479, 12569, 12589, 12689, 13457, 13469, 13567, 13679, 13789, 15679, 23459, 23567, 23689, 23789, 25679, 34589, 34679, 123457, 123479, 124567, 124679, 125789, 134789, 145679, 234589, 235679, 235789, 245789, 345679, 345689, 1234789, 1235789, 1245689, 1456789, 12356789, 23456789]</pre>
Line 1,344:
<code>powerset</code> is defined at [[Power set#Quackery]], and <code>isprime</code> is defined at [[Primality by trial division#Quackery]].
 
<langsyntaxhighlight lang=Quackery> [ 0 swap witheach
[ swap 10 * + ] ] is digits->n ( [ --> n )
 
Line 1,352:
[ digits->n dup isprime
iff join else drop ]
sort echo</langsyntaxhighlight>
 
{{out}}
Line 1,360:
 
=={{header|Raku}}==
<langsyntaxhighlight lang=perl6>put (flat 2, 3, 5, 7, sort +*, gather (1..8).map: &recurse ).batch(10)».fmt("%8d").join: "\n";
 
sub recurse ($str) {
Line 1,367:
}
 
printf "%.3f seconds", now - INIT now;</langsyntaxhighlight>
{{out}}
<pre> 2 3 5 7 13 17 19 23 29 37
Line 1,382:
 
=={{header|Ring}}==
<langsyntaxhighlight lang=ring>show("ascending primes", sort(cending_primes(seq(1, 9))))
 
func show(title, itm)
Line 1,421:
func fmt(x, l)
res = " " + x
return right(res, l)</langsyntaxhighlight>
{{out}}
<pre>100 ascending primes:
Line 1,446:
 
=={{header|Ruby}}==
<langsyntaxhighlight lang=ruby>require 'prime'
 
digits = [9,8,7,6,5,4,3,2,1]
Line 1,456:
end
 
puts res.join(",")</langsyntaxhighlight>
{{out}}
<pre>2,3,5,7,13,17,19,23,29,37,47,59,67,79,89,127,137,139,149,157,167,179,239,257,269,347,349,359,367,379,389,457,467,479,569,1237,1249,1259,1279,1289,1367,1459,1489,1567,1579,1789,2347,2357,2389,2459,2467,2579,2689,2789,3457,3467,3469,4567,4679,4789,5689,12347,12379,12457,12479,12569,12589,12689,13457,13469,13567,13679,13789,15679,23459,23567,23689,23789,25679,34589,34679,123457,123479,124567,124679,125789,134789,145679,234589,235679,235789,245789,345679,345689,1234789,1235789,1245689,1456789,12356789,23456789
</pre>
=={{header|Sidef}}==
<langsyntaxhighlight lang=ruby>func primes_with_ascending_digits(base = 10) {
 
var list = []
Line 1,489:
arr.each_slice(10, {|*a|
say a.map { '%8s' % _ }.join(' ')
})</langsyntaxhighlight>
{{out}}
<pre>
Line 1,508:
=={{header|Visual Basic .NET}}==
{{trans|Pascal, C#, C++, C, Fortran}}
<langsyntaxhighlight lang=vbnet>Module AscendingPrimes
 
Function isPrime(n As Integer)
Line 1,555:
End Sub
 
End Module</langsyntaxhighlight>
{{Output}}
<pre>2 3 5 7 13 17 19 23 29 37 47 59 67 79 89 127 137 139 149 157 167 179 239 257 269 347 349 359 367 379 389 457 467 479 569 1237 1249 1259 1279 1289 1367 1459 1489 1567 1579 1789 2347 2357 2389 2459 2467 2579 2689 2789 3457 3467 3469 4567 4679 4789 5689 12347 12379 12457 12479 12569 12589 12689 13457 13469 13567 13679 13789 15679 23459 23567 23689 23789 25679 34589 34679 123457 123479 124567 124679 125789 134789 145679 234589 235679 235789 245789 345679 345689 1234789 1235789 1245689 1456789 12356789 23456789</pre>
Line 1,561:
=={{header|Vlang}}==
{{trans|Go}}
<langsyntaxhighlight lang=vlang>fn is_prime(n int) bool {
if n < 2 {
return false
Line 1,617:
}
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,640:
===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.
<langsyntaxhighlight lang=ecmascript>import "./math" for Int
import "./seq" for Lst
import "./fmt" for Fmt
Line 1,665:
ascPrimes.addAll(higherPrimes)
System.print("There are %(ascPrimes.count) ascending primes, namely:")
for (chunk in Lst.chunks(ascPrimes, 10)) Fmt.print("$8d", chunk)</langsyntaxhighlight>
 
{{out}}
Line 1,686:
 
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.
<langsyntaxhighlight lang=ecmascript>import "./set" for Set
import "./math" for Int
import "./seq" for Lst
Line 1,711:
ascPrimes.sort()
System.print("There are %(ascPrimes.count) ascending primes, namely:")
for (chunk in Lst.chunks(ascPrimes, 10)) Fmt.print("$8s", chunk)</langsyntaxhighlight>
 
{{out}}
Line 1,720:
=={{header|XPL0}}==
Brute force solution: 4.3 seconds on Pi4.
<langsyntaxhighlight lang=XPL0>func IsPrime(N); \Return 'true' if N is prime
int N, I;
[if N <= 2 then return N = 2;
Line 1,753:
if rem(Cnt/10) = 0 then CrLf(0);
];
]</langsyntaxhighlight>
 
{{out}}
Line 1,771:
===powerset===
Aaah! Power set, from Factor. Runs in less than 1 millisecond. A better way of measuring duration than using Linux's time utility gave a more credible 35 milliseconds.
<langsyntaxhighlight lang=XPL0>include xpllib; \provides IsPrime and Sort
 
int I, N, Mask, Digit, A(512), Cnt;
Line 1,795:
];
];
]</langsyntaxhighlight>
 
{{out}}
10,333

edits