Primes with digits in nondecreasing order: Difference between revisions

Content added Content deleted
(Frink)
m (syntax highlighting fixup automation)
Line 9: Line 9:
{{trans|Nim}}
{{trans|Nim}}


<lang 11l>F is_prime(a)
<syntaxhighlight lang="11l">F is_prime(a)
I a == 2
I a == 2
R 1B
R 1B
Line 34: Line 34:
print(‘#3’.format(n), end' I c % 10 == 0 {"\n"} E ‘ ’)
print(‘#3’.format(n), end' I c % 10 == 0 {"\n"} E ‘ ’)
print()
print()
print(‘Found ’c‘ primes with digits in nondecreasing order’)</lang>
print(‘Found ’c‘ primes with digits in nondecreasing order’)</syntaxhighlight>


{{out}}
{{out}}
Line 49: Line 49:
=={{header|Action!}}==
=={{header|Action!}}==
{{libheader|Action! Sieve of Eratosthenes}}
{{libheader|Action! Sieve of Eratosthenes}}
<lang Action!>INCLUDE "H6:SIEVE.ACT"
<syntaxhighlight lang="action!">INCLUDE "H6:SIEVE.ACT"


BYTE FUNC NonDecreasingDigits(INT x)
BYTE FUNC NonDecreasingDigits(INT x)
Line 81: Line 81:
OD
OD
PrintF("%E%EThere are %I primes",count)
PrintF("%E%EThere are %I primes",count)
RETURN</lang>
RETURN</syntaxhighlight>
{{out}}
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Primes_with_digits_in_nondecreasing_order.png Screenshot from Atari 8-bit computer]
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Primes_with_digits_in_nondecreasing_order.png Screenshot from Atari 8-bit computer]
Line 93: Line 93:
=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
{{libheader|ALGOL 68-primes}}
{{libheader|ALGOL 68-primes}}
<lang algol68>BEGIN # find primes where the digits are non-descending #
<syntaxhighlight lang="algol68">BEGIN # find primes where the digits are non-descending #
INT max number = 1000;
INT max number = 1000;
# sieve the primes to max number #
# sieve the primes to max number #
Line 129: Line 129:
)
)
)
)
END</lang>
END</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 143: Line 143:
=={{header|APL}}==
=={{header|APL}}==
{{works with|Dyalog APL}}
{{works with|Dyalog APL}}
<lang APL>(⊢(/⍨)(∧/2≤/10(⊥⍣¯1)⊢)¨)∘(⊢(/⍨)(2=0+.=⍳|⊢)¨)⍳1000</lang>
<syntaxhighlight lang="apl">(⊢(/⍨)(∧/2≤/10(⊥⍣¯1)⊢)¨)∘(⊢(/⍨)(2=0+.=⍳|⊢)¨)⍳1000</syntaxhighlight>
{{out}}
{{out}}
<pre>2 3 5 7 11 13 17 19 23 29 37 47 59 67 79 89 113 127 137 139 149 157 167
<pre>2 3 5 7 11 13 17 19 23 29 37 47 59 67 79 89 113 127 137 139 149 157 167
Line 151: Line 151:
=={{header|Arturo}}==
=={{header|Arturo}}==


<lang rebol>primes: select 1..1000 => prime?
<syntaxhighlight lang="rebol">primes: select 1..1000 => prime?
nondecreasing?: function [n][
nondecreasing?: function [n][
ds: digits n
ds: digits n
Line 166: Line 166:


loop split.every: 10 select primes => nondecreasing? 'a ->
loop split.every: 10 select primes => nondecreasing? 'a ->
print map a => [pad to :string & 4]</lang>
print map a => [pad to :string & 4]</syntaxhighlight>


{{out}}
{{out}}
Line 177: Line 177:


=={{header|AWK}}==
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f PRIMES_WITH_DIGITS_IN_NONDECREASING_ORDER.AWK
# syntax: GAWK -f PRIMES_WITH_DIGITS_IN_NONDECREASING_ORDER.AWK
BEGIN {
BEGIN {
Line 209: Line 209:
return(1)
return(1)
}
}
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 223: Line 223:
=={{header|BASIC}}==
=={{header|BASIC}}==
{{works with|QBasic}}
{{works with|QBasic}}
<lang basic>10 DEFINT A-Z
<syntaxhighlight lang="basic">10 DEFINT A-Z
20 DIM P(1000)
20 DIM P(1000)
30 P(0)=-1: P(1)=-1
30 P(0)=-1: P(1)=-1
Line 232: Line 232:
80 N=A*100+B*10+C
80 N=A*100+B*10+C
90 IF P(N)=0 THEN PRINT N,
90 IF P(N)=0 THEN PRINT N,
100 NEXT C,B,A</lang>
100 NEXT C,B,A</syntaxhighlight>
{{out}}
{{out}}
<pre> 2 3 5 7 11
<pre> 2 3 5 7 11
Line 247: Line 247:


==={{header|BASIC256}}===
==={{header|BASIC256}}===
<lang BASIC256>function isPrime(v)
<syntaxhighlight lang="basic256">function isPrime(v)
if v < 2 then return False
if v < 2 then return False
if v mod 2 = 0 then return v = 2
if v mod 2 = 0 then return v = 2
Line 279: Line 279:
next i
next i
print chr(10); c; " such primes found."
print chr(10); c; " such primes found."
end</lang>
end</syntaxhighlight>


==={{header|PureBasic}}===
==={{header|PureBasic}}===
<lang PureBasic>Procedure isPrime(v.i)
<syntaxhighlight lang="purebasic">Procedure isPrime(v.i)
If v <= 1 : ProcedureReturn #False
If v <= 1 : ProcedureReturn #False
ElseIf v < 4 : ProcedureReturn #True
ElseIf v < 4 : ProcedureReturn #True
Line 325: Line 325:
Next i
Next i
PrintN(#CRLF$ + Str(c) + " such primes found."): Input()
PrintN(#CRLF$ + Str(c) + " such primes found."): Input()
CloseConsole()</lang>
CloseConsole()</syntaxhighlight>


==={{header|Yabasic}}===
==={{header|Yabasic}}===
<lang yabasic>sub isPrime(v)
<syntaxhighlight lang="yabasic">sub isPrime(v)
if v < 2 then return False : fi
if v < 2 then return False : fi
if mod(v, 2) = 0 then return v = 2 : fi
if mod(v, 2) = 0 then return v = 2 : fi
Line 360: Line 360:
next i
next i
print chr$(10), c, " such primes found."
print chr$(10), c, " such primes found."
end</lang>
end</syntaxhighlight>




=={{header|BCPL}}==
=={{header|BCPL}}==
<lang bcpl>get "libhdr";
<syntaxhighlight lang="bcpl">get "libhdr";


let sieve(prime, max) be
let sieve(prime, max) be
Line 396: Line 396:
$)
$)
freevec(prime)
freevec(prime)
$)</lang>
$)</syntaxhighlight>
{{out}}
{{out}}
<pre> 2 3 5 7 11 13 17 19 23 29
<pre> 2 3 5 7 11 13 17 19 23 29
Line 406: Line 406:
=={{header|C#|CSharp}}==
=={{header|C#|CSharp}}==
The ''chars'' array explicitly enforces the case order, not relying on the language's idea of what letters are before or after each other.
The ''chars'' array explicitly enforces the case order, not relying on the language's idea of what letters are before or after each other.
<lang csharp>using System.Linq; using System.Collections.Generic; using static System.Console; using static System.Math;
<syntaxhighlight lang="csharp">using System.Linq; using System.Collections.Generic; using static System.Console; using static System.Math;
class Program {
class Program {
Line 438: Line 438:
if (!flags[j]) { yield return j;
if (!flags[j]) { yield return j;
for (int k = sq, i = j << 1; k <= lim; k += i) flags[k] = true; }
for (int k = sq, i = j << 1; k <= lim; k += i) flags[k] = true; }
for (; j <= lim; j += 2) if (!flags[j]) yield return j; } }</lang>
for (; j <= lim; j += 2) if (!flags[j]) yield return j; } }</syntaxhighlight>
{{out}}
{{out}}
<pre style="height:20em"> 11 111 11111 1111111
<pre style="height:20em"> 11 111 11111 1111111
Line 516: Line 516:
=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_functions Extensible Prime Generator (F#)]
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_functions Extensible Prime Generator (F#)]
<lang fsharp>
<syntaxhighlight lang="fsharp">
// Primes with digits in nondecreasing order: Nigel Galloway. May 16th., 2021
// Primes with digits in nondecreasing order: Nigel Galloway. May 16th., 2021
let rec fN g=function n when n<10->(n<=g) |n when (n%10)<=g->fN(n%10)(n/10) |_->false
let rec fN g=function n when n<10->(n<=g) |n when (n%10)<=g->fN(n%10)(n/10) |_->false
let fN=fN 9 in primes32()|>Seq.takeWhile((>)1000)|>Seq.filter fN|>Seq.iter(printf "%d "); printfn ""
let fN=fN 9 in primes32()|>Seq.takeWhile((>)1000)|>Seq.filter fN|>Seq.iter(printf "%d "); printfn ""
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 527: Line 527:
=={{header|Factor}}==
=={{header|Factor}}==
{{works with|Factor|0.99 2021-02-05}}
{{works with|Factor|0.99 2021-02-05}}
<lang factor>USING: grouping lists lists.lazy math math.primes.lists
<syntaxhighlight lang="factor">USING: grouping lists lists.lazy math math.primes.lists
present prettyprint ;
present prettyprint ;


lprimes [ present [ <= ] monotonic? ] lfilter
lprimes [ present [ <= ] monotonic? ] lfilter
[ 1000 < ] lwhile [ . ] leach</lang>
[ 1000 < ] lwhile [ . ] leach</syntaxhighlight>
{{out}}
{{out}}
<pre style="height:14em">
<pre style="height:14em">
Line 587: Line 587:


=={{header|J}}==
=={{header|J}}==
<lang j>echo (([:*./2<:/\10#.^:_1])"0#])@(i.&.(p:^:_1)) 1000
<syntaxhighlight lang="j">echo (([:*./2<:/\10#.^:_1])"0#])@(i.&.(p:^:_1)) 1000
exit 0</lang>
exit 0</syntaxhighlight>
{{out}}
{{out}}
<pre>2 3 5 7 11 13 17 19 23 29 37 47 59 67 79 89 113 127 137 139 149 157 167 179 199 223 227 229 233 239 257 269 277 337 347 349 359 367 379 389 449 457 467 479 499 557 569 577 599 677</pre>
<pre>2 3 5 7 11 13 17 19 23 29 37 47 59 67 79 89 113 127 137 139 149 157 167 179 199 223 227 229 233 239 257 269 277 337 347 349 359 367 379 389 449 457 467 479 499 557 569 577 599 677</pre>
=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>#include "isprime.bas"
<syntaxhighlight lang="freebasic">#include "isprime.bas"


function is_ndp( byval n as integer ) as boolean
function is_ndp( byval n as integer ) as boolean
Line 608: Line 608:
for i as uinteger = 2 to 999
for i as uinteger = 2 to 999
if isprime(i) andalso is_ndp(i) then print i;" ";
if isprime(i) andalso is_ndp(i) then print i;" ";
next i : print</lang>
next i : print</syntaxhighlight>
{{out}}<pre>2 3 5 7 11 13 17 19 23 29 37 47 59 67 79 89 113 127 137 139 149 157 167 179 199 223 227 229 233 239 257 269 277 337 347 349 359 367 379 389 449 457 467 479 499 557 569 577 599 677</pre>
{{out}}<pre>2 3 5 7 11 13 17 19 23 29 37 47 59 67 79 89 113 127 137 139 149 157 167 179 199 223 227 229 233 239 257 269 277 337 347 349 359 367 379 389 449 457 467 479 499 557 569 577 599 677</pre>


=={{header|Frink}}==
=={{header|Frink}}==
<lang frink>for n = primes[2,1000]
<syntaxhighlight lang="frink">for n = primes[2,1000]
if sort[integerDigits[n]] == integerDigits[n]
if sort[integerDigits[n]] == integerDigits[n]
print["$n "]</lang>
print["$n "]</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 623: Line 623:
{{trans|Wren}}
{{trans|Wren}}
{{libheader|Go-rcu}}
{{libheader|Go-rcu}}
<lang go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 660: Line 660:
}
}
fmt.Printf("\n%d such primes found.\n", len(nonDesc))
fmt.Printf("\n%d such primes found.\n", len(nonDesc))
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 679: Line 679:


See e.g. [[Erd%C5%91s-primes#jq]] for a suitable implementation of `is_prime`.
See e.g. [[Erd%C5%91s-primes#jq]] for a suitable implementation of `is_prime`.
<lang jq>def digits: tostring | explode;
<syntaxhighlight lang="jq">def digits: tostring | explode;


# Input: an upper bound, or `infinite`
# Input: an upper bound, or `infinite`
Line 687: Line 687:
| select( (digits | (. == sort)) and is_prime);
| select( (digits | (. == sort)) and is_prime);


1000 | primes_with_nondecreasing_digits</lang>
1000 | primes_with_nondecreasing_digits</syntaxhighlight>
{{out}} (abbreviated)
{{out}} (abbreviated)
<pre>
<pre>
Line 706: Line 706:
{{trans|Raku}}
{{trans|Raku}}
Note for the case-sensitive digits base 62 example: Julia defaults to 'A' < 'a' in sorting. So Aa is in order, but aA is not nondecreasing.
Note for the case-sensitive digits base 62 example: Julia defaults to 'A' < 'a' in sorting. So Aa is in order, but aA is not nondecreasing.
<lang julia>using Primes
<syntaxhighlight lang="julia">using Primes


const range = 2:999
const range = 2:999
Line 716: Line 716:
foreach(p -> print(lpad(string(p[2], base=base), 5), p[1] % 16 == 0 ? "\n" : ""), enumerate(primes))
foreach(p -> print(lpad(string(p[2], base=base), 5), p[1] % 16 == 0 ? "\n" : ""), enumerate(primes))
end
end
</lang>{{out}}
</syntaxhighlight>{{out}}
<pre>
<pre>
Base 2: 4 non-descending primes between 1 and 1111111:
Base 2: 4 non-descending primes between 1 and 1111111:
Line 792: Line 792:


=={{header|Ksh}}==
=={{header|Ksh}}==
<lang ksh>
<syntaxhighlight lang="ksh">
#!/bin/ksh
#!/bin/ksh


Line 841: Line 841:
done
done
printf "\n%d Primes with digits in nondecreasing order < %d\n" ${cnt} $MAXPRIME
printf "\n%d Primes with digits in nondecreasing order < %d\n" ${cnt} $MAXPRIME
</syntaxhighlight>
</lang>
{{out}}<pre>
{{out}}<pre>
3 5 7 11 13 17 19 23 29 37 47 59 67 79 89 113 127 137 139 149 157 167 179 199 223 227 229 233 239 257 269 277 337 347 349 359 367 379 389 449 457 467 479 499 557 569 577 599 677
3 5 7 11 13 17 19 23 29 37 47 59 67 79 89 113 127 137 139 149 157 167 179 199 223 227 229 233 239 257 269 277 337 347 349 359 367 379 389 449 457 467 479 499 557 569 577 599 677
Line 847: Line 847:


=={{header|MAD}}==
=={{header|MAD}}==
<lang MAD> NORMAL MODE IS INTEGER
<syntaxhighlight lang="mad"> NORMAL MODE IS INTEGER
BOOLEAN PRIME
BOOLEAN PRIME
DIMENSION PRIME(1000), COL(10)
DIMENSION PRIME(1000), COL(10)
Line 877: Line 877:
TEST CONTINUE
TEST CONTINUE
VECTOR VALUES CFMT = $10(I4)*$
VECTOR VALUES CFMT = $10(I4)*$
END OF PROGRAM </lang>
END OF PROGRAM </syntaxhighlight>
{{out}}
{{out}}
<pre> 2 3 5 7 11 13 17 19 23 29
<pre> 2 3 5 7 11 13 17 19 23 29
Line 885: Line 885:
449 457 467 479 499 557 569 577 599 677</pre>
449 457 467 479 499 557 569 577 599 677</pre>
=={{header|Mathematica}} / {{header|Wolfram Language}}==
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<lang Mathematica>Partition[
<syntaxhighlight lang="mathematica">Partition[
Cases[Most@
Cases[Most@
NestWhileList[NextPrime,
NestWhileList[NextPrime,
2, # < 1000 &], _?(OrderedQ[IntegerDigits@#] &)],
2, # < 1000 &], _?(OrderedQ[IntegerDigits@#] &)],
UpTo[10]] // TableForm</lang>
UpTo[10]] // TableForm</syntaxhighlight>


{{out}}<pre>
{{out}}<pre>
Line 900: Line 900:


=={{header|Nim}}==
=={{header|Nim}}==
<lang Nim>import strformat, sugar
<syntaxhighlight lang="nim">import strformat, sugar


func isPrime(n: Natural): bool =
func isPrime(n: Natural): bool =
Line 930: Line 930:
echo &"Found {result.len} primes:"
echo &"Found {result.len} primes:"
for i, n in result:
for i, n in result:
stdout.write &"{n:3}", if (i + 1) mod 10 == 0: '\n' else: ' '</lang>
stdout.write &"{n:3}", if (i + 1) mod 10 == 0: '\n' else: ' '</syntaxhighlight>


{{out}}
{{out}}
Line 941: Line 941:


=={{header|Phix}}==
=={{header|Phix}}==
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">function</span> <span style="color: #000000;">nd</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">return</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">=</span><span style="color: #7060A8;">sort</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">nd</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">return</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">=</span><span style="color: #7060A8;">sort</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">filter</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;">"%d"</span><span style="color: #0000FF;">},</span><span style="color: #7060A8;">get_primes_le</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1000</span><span style="color: #0000FF;">)}),</span><span style="color: #000000;">nd</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: #7060A8;">filter</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;">"%d"</span><span style="color: #0000FF;">},</span><span style="color: #7060A8;">get_primes_le</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1000</span><span style="color: #0000FF;">)}),</span><span style="color: #000000;">nd</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;">"%d non-decreasing primes &lt; 1,000: %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">shorten</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</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;">"%d non-decreasing primes &lt; 1,000: %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">shorten</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">))})</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{out}}
<pre>
<pre>
Line 953: Line 953:
=={{header|Perl}}==
=={{header|Perl}}==
{{libheader|ntheory}}
{{libheader|ntheory}}
<lang perl>#!/usr/bin/perl
<syntaxhighlight lang="perl">#!/usr/bin/perl


use strict;
use strict;
Line 960: Line 960:


my @want = grep ! /(.)(.)(??{$1 > $2 ? '' : '(*FAIL)'})/, @{ primes(1000) };
my @want = grep ! /(.)(.)(??{$1 > $2 ? '' : '(*FAIL)'})/, @{ primes(1000) };
print "@want" =~ s/.{50}\K /\n/gr . "\n\ncount: " . @want . "\n";</lang>
print "@want" =~ s/.{50}\K /\n/gr . "\n\ncount: " . @want . "\n";</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 972: Line 972:


=={{header|Plain English}}==
=={{header|Plain English}}==
<lang plainenglish>To run:
<syntaxhighlight lang="plainenglish">To run:
Start up.
Start up.
Loop.
Loop.
Line 995: Line 995:
If the number is not prime, say no.
If the number is not prime, say no.
If the number is not non-decreasing, say no.
If the number is not non-decreasing, say no.
Say yes.</lang>
Say yes.</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,002: Line 1,002:


=={{header|PL/M}}==
=={{header|PL/M}}==
<lang plm>100H:
<syntaxhighlight lang="plm">100H:
BDOS: PROCEDURE (FN, ARG); DECLARE FN BYTE, ARG ADDRESS; GO TO 5; END BDOS;
BDOS: PROCEDURE (FN, ARG); DECLARE FN BYTE, ARG ADDRESS; GO TO 5; END BDOS;
EXIT: PROCEDURE; CALL BDOS(0,0); END EXIT;
EXIT: PROCEDURE; CALL BDOS(0,0); END EXIT;
Line 1,058: Line 1,058:
END;
END;
CALL EXIT;
CALL EXIT;
EOF</lang>
EOF</syntaxhighlight>
{{out}}
{{out}}
<pre>2 3 5 7 11 13 17 19 23 29
<pre>2 3 5 7 11 13 17 19 23 29
Line 1,067: Line 1,067:


=={{header|Python}}==
=={{header|Python}}==
<lang python>'''Primes with monotonic (rising or equal) digits'''
<syntaxhighlight lang="python">'''Primes with monotonic (rising or equal) digits'''


from operator import le
from operator import le
Line 1,182: Line 1,182:
if __name__ == '__main__':
if __name__ == '__main__':
main()
main()
</syntaxhighlight>
</lang>
{{Out}}
{{Out}}
<pre>50 matches for base 10:
<pre>50 matches for base 10:
Line 1,193: Line 1,193:


=={{header|Raku}}==
=={{header|Raku}}==
<lang perl6>my $range = ^1000;
<syntaxhighlight lang="raku" line>my $range = ^1000;


for flat 2..10, 17, 27, 31 -> $base {
for flat 2..10, 17, 27, 31 -> $base {
Line 1,199: Line 1,199:
.batch(20)».fmt("%{.tail.chars}s").join: "\n" }"
.batch(20)».fmt("%{.tail.chars}s").join: "\n" }"
given $range.grep( *.is-prime ).map( *.base: $base ).grep: { [le] .comb }
given $range.grep( *.is-prime ).map( *.base: $base ).grep: { [le] .comb }
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>Base 2: 4 non-decending primes between 0 and 1111100111:
<pre>Base 2: 4 non-decending primes between 0 and 1111100111:
Line 1,259: Line 1,259:


=={{header|REXX}}==
=={{header|REXX}}==
<lang rexx>/*REXX program finds & displays primes whose decimal digits are in non─decreasing order.*/
<syntaxhighlight lang="rexx">/*REXX program finds & displays primes whose decimal digits are in non─decreasing order.*/
parse arg n cols . /*obtain optional argument from the CL.*/
parse arg n cols . /*obtain optional argument from the CL.*/
if n=='' | n=="," then n= 1000 /*Not specified? Then use the default.*/
if n=='' | n=="," then n= 1000 /*Not specified? Then use the default.*/
Line 1,302: Line 1,302:
end /*k*/ /* [↑] only process numbers ≤ √ J */
end /*k*/ /* [↑] only process numbers ≤ √ J */
#= #+1; @.#= j; s.#= j*j /*bump # of Ps; assign next P; P²; P# */
#= #+1; @.#= j; s.#= j*j /*bump # of Ps; assign next P; P²; P# */
end /*j*/; return</lang>
end /*j*/; return</syntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
<pre>
Line 1,318: Line 1,318:


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>load "stdlib.ring"
<syntaxhighlight lang="ring">load "stdlib.ring"
? "working..."
? "working..."
Line 1,351: Line 1,351:
s = string(x) l = len(s)
s = string(x) l = len(s)
if l > y y = l ok
if l > y y = l ok
return substr(" ", 11 - y + l) + s</lang>
return substr(" ", 11 - y + l) + s</syntaxhighlight>
{{out}}
{{out}}
<pre>working...
<pre>working...
Line 1,365: Line 1,365:


=={{header|Seed7}}==
=={{header|Seed7}}==
<lang seed7>$ include "seed7_05.s7i";
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";




Line 1,415: Line 1,415:
end if;
end if;
end for;
end for;
end func;</lang>
end func;</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,423: Line 1,423:
=={{header|Sidef}}==
=={{header|Sidef}}==
Simple solution:
Simple solution:
<lang ruby>say 1000.primes.grep { .digits.cons(2).all { .head >= .tail } }</lang>
<syntaxhighlight lang="ruby">say 1000.primes.grep { .digits.cons(2).all { .head >= .tail } }</syntaxhighlight>


Generate such primes from digits (asymptotically faster):
Generate such primes from digits (asymptotically faster):
<lang ruby>func primes_with_nondecreasing_digits(upto, base = 10) {
<syntaxhighlight lang="ruby">func primes_with_nondecreasing_digits(upto, base = 10) {


upto = prev_prime(upto+1)
upto = prev_prime(upto+1)
Line 1,451: Line 1,451:
}
}


say primes_with_nondecreasing_digits(1000)</lang>
say primes_with_nondecreasing_digits(1000)</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,459: Line 1,459:
=={{header|Visual Basic .NET}}==
=={{header|Visual Basic .NET}}==
{{trans|C#}}
{{trans|C#}}
<lang vbnet>Imports System.Linq
<syntaxhighlight lang="vbnet">Imports System.Linq
Imports System.Collections.Generic
Imports System.Collections.Generic
Imports System.Console
Imports System.Console
Line 1,513: Line 1,513:
Next
Next
End Sub
End Sub
End Module</lang>
End Module</syntaxhighlight>
{{out}}
{{out}}
Same as C#.
Same as C#.
Line 1,521: Line 1,521:
{{libheader|Wren-seq}}
{{libheader|Wren-seq}}
{{libheader|Wren-fmt}}
{{libheader|Wren-fmt}}
<lang ecmascript>import "/math" for Int
<syntaxhighlight lang="ecmascript">import "/math" for Int
import "/seq" for Lst
import "/seq" for Lst
import "/fmt" for Fmt
import "/fmt" for Fmt
Line 1,542: Line 1,542:
System.print("Primes below 1,000 with digits in non-decreasing order:")
System.print("Primes below 1,000 with digits in non-decreasing order:")
for (chunk in Lst.chunks(nonDesc, 10)) Fmt.print("$3d", chunk)
for (chunk in Lst.chunks(nonDesc, 10)) Fmt.print("$3d", chunk)
System.print("\n%(nonDesc.count) such primes found.")</lang>
System.print("\n%(nonDesc.count) such primes found.")</syntaxhighlight>


{{out}}
{{out}}
Line 1,557: Line 1,557:


=={{header|XPL0}}==
=={{header|XPL0}}==
<lang XPL0>func IsPrime(N); \Return 'true' if N is a prime number
<syntaxhighlight lang="xpl0">func IsPrime(N); \Return 'true' if N is a prime number
int N, I;
int N, I;
[if N <= 1 then return false;
[if N <= 1 then return false;
Line 1,592: Line 1,592:
Text(0, " primes found with nondecreasing digits below 1000.
Text(0, " primes found with nondecreasing digits below 1000.
");
");
]</lang>
]</syntaxhighlight>


{{out}}
{{out}}