Ascending primes: Difference between revisions

no edit summary
(→‎OCaml: add)
No edit summary
Line 1,601:
34679 123457 123479 124567 124679 125789 134789 145679 234589 235679
235789 245789 345679 345689 1234789 1235789 1245689 1456789 12356789 23456789
</pre>
 
=={{header|SparForte}}==
{{trans|Pascal}}
<syntaxhighlight lang="ada">
#!/usr/local/bin/spar
pragma annotate( summary, "primes_asc" );
pragma annotate( description, "Generate and show all primes with strictly ascending decimal digits" );
pragma annotate( description, "Translation of Pascal" );
pragma annotate( see_also, "https://rosettacode.org/wiki/Ascending_primes" );
pragma annotate( author, "Ken O. Burtch" );
 
pragma software_model( nonstandard );
pragma restriction( no_external_commands );
 
procedure primes_asc is
maxsize : constant natural := 1000;
 
queue : array(1..maxsize) of natural;
primes: array(1..maxsize) of natural;
 
b : natural;
e : natural;
n : natural;
v : natural;
 
function is_prime(num: integer) return boolean is
found : boolean;
num_root : natural;
k : natural;
begin
if num = 2 then
found := true;
elsif (num = 1) or (num mod 2 = 0) then
found := false;
else
num_root := numerics.truncation(numerics.sqrt(num));
found;
k := 3;
while found and (k <= num_root) loop
if num mod k = 0 then
found := false;
else
k := @ + 2;
end if;
end loop;
end if;
return found;
end is_prime;
 
begin
b := 1;
e := 1;
n := 0;
 
for k in 1..9 loop
queue(e) := k;
e := e + 1;
end loop;
 
while b < e loop
v := queue(b);
b := @ + 1;
if is_prime(v) then
n := @ + 1;
primes(n) := v;
end if;
 
for k in v mod 10 + 1..9 loop
queue(e) := v * 10 + k;
e := @ + 1;
end loop;
end loop;
 
for k in 1..n loop
put(primes(k), "ZZZZZZZZ9");
if k mod 8 = 0 then
new_line;
end if;
end loop;
new_line;
end primes_asc;</syntaxhighlight>
{{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>
 
76

edits