Primes with digits in nondecreasing order: Difference between revisions

m
→‎{{header|REXX}}: used simpler coding, used a better grid.
(Added Arturo implementation)
m (→‎{{header|REXX}}: used simpler coding, used a better grid.)
Line 649:
=={{header|REXX}}==
<lang rexx>/*REXX program finds & displays primes whose decimal digits are in non─decreasing order.*/
parse arg hin cols . /*obtain optional argument from the CL.*/
if hi n=='' | hi n=="," then hi n= 1000 /*Not specified? Then use the default.*/
if cols=='' | cols=="," then cols= 10 /* " " " " " " */
call genP /*build array of semaphores for primes.*/
w= 10 /*width of a number in any column. */
@ndcps title= ' primes whose decimal digits are in' non─decreasing order that' ,
'arenon─decreasing order, N < ' commas(hin)
if cols>0 then say ' index │'center(@ndcpstitle, 1 + cols*(w+1) )
if cols>0 then say '───────┼'center("" , 1 + cols*(w+1), '─')
ndcpsfound= 0; idx= 1 /*initialize # of non─decreasing primes*/
$= /*a list of non─decreasing digit primes*/
do j=1 while @.j<hin; p= @.j /*examine the primes within the range. */
do k=1 for length(p)-1 /*validate that it meets specifications*/
if substr(p, k, 1) > substr(p, k+1, 1) then iterate j /*compare dig with next.*/
end /*k*/
ndcpsfound= ndcpsfound + 1 /*bump number of non─decreasing primes.*/
if cols==<0 then iterate /*BuildJust do the listsummary? (toThen be shown later)?skip grid.*/
c$= $ right( commas(pj), w) /*maybe add commasa tocommatized theprime──►list number(grid). */
$if found//cols\==0 $ right(c, max(w, length(c)then ) )iterate /*addhave awe primepopulated a ──►line list,of allowoutput? big nums.*/
if ndcps//cols\==0 then iterate /*have we populated a line of output? */
say center(idx, 7)'│' substr($, 2); $= /*display what we have so far (cols). */
idx= idx + cols /*bump the index count for the output*/
Line 674 ⟶ 673:
 
if $\=='' then say center(idx, 7)"│" substr($, 2) /*possible display residual output.*/
if cols>0 then say '───────┴'center("" , 1 + cols*(w+1), '─') /*display foot sep. */
say
say 'Found ' commas(ndcpsfound) @ndcpstitle /*display foot title*/
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
Line 683:
#= 3; s.#= @.# **2 /*number of primes so far; prime². */
/* [↓] generate more primes ≤ high.*/
do j=@.#+2 by 2 to hi n-1 /*find odd primes from here on. */
parse var j '' -1 _; if _==5 then iterate /*J divisible by 5? (right dig)*/
if j// 3==0 then iterate /*" " " 3? */
Line 694:
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
index │ primes whose decimal digits are in non─decreasing order, that areN < 1,000
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ 21 32 53 74 11 5 13 6 17 7 8 19 239 2910
11 │ 3712 4715 5917 6719 7922 8924 113 30 127 31 137 33 139 34
21 │ 149 35 157 37 167 39 179 41 199 46 223 48 227 49 229 23350 239 51 52
31 │ 257 55 269 57 277 59 337 68 347 69 349 70 359 72 367 37973 389 75 77
41 │ 449 87 457 88 467 91 479 92 499 95 557 102 569 104 577 106 599 109 677 123
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────
 
Found 50 primes whose decimal digits are in non─decreasing order, that areN < 1,000
</pre>