Special divisors: Difference between revisions

m
→‎{{header|REXX}}: added the computer programming language REXX.
(→‎{{header|Raku}}: Add a Raku example)
m (→‎{{header|REXX}}: added the computer programming language REXX.)
Line 19:
157 163 167 169 173 179 181 187 191 193
197 199</pre>
 
=={{header|REXX}}==
<lang rexx>/*REXX program finds special divisorsa: numbers N such that reverse(D) divides */
/*───────────────────────────────────────────── reverse(N) for all divisors D of N. */
parse arg hi cols . /*obtain optional argument from the CL.*/
if hi=='' | hi=="," then hi= 200 /* " " " " " " */
if cols=='' | cols=="," then cols= 10 /* " " " " " " */
w= 10 /*width of a number in any column. */
@sds= ' special divisors N that reverse(D) divides reverse(N)' ,
'for all divisors D of N, where N < ' commas(hi)
if cols>0 then say ' index │'center(@sds, 1 + cols*(w+1) )
if cols>0 then say '───────┼'center("" , 1 + cols*(w+1), '─')
sds= 0; idx= 1 /*initialize # of nice primes and index*/
$= /*a list of nice primes (so far). */
do j=1 to hi-1; r= reverse(j)
do k=2 to j%2 /*skip the first divisor (unity) & last*/
if j//k==0 then if r//reverse(k)==0 then nop
else iterate j
end /*m*/
sds= sds + 1 /*bump the number of sds numbers. */
if cols==0 then iterate /*Build the list (to be shown later)? */
c= commas(j) /*maybe add commas to the number. */
$= $ right(c, max(w, length(c) ) ) /*add a nice prime ──► list, allow big#*/
if sds//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*/
end /*j*/
 
if $\=='' then say center(idx, 7)"│" substr($, 2) /*possible display residual output.*/
say
say 'Found ' commas(sds) @sds
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?</lang>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
index │ special divisors N that reverse(D) divides reverse(N) for all divisors D of N, where N < 200
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ 1 2 3 4 5 6 7 8 9 11
11 │ 13 17 19 22 23 26 27 29 31 33
21 │ 37 39 41 43 44 46 47 53 55 59
31 │ 61 62 66 67 69 71 73 77 79 82
41 │ 83 86 88 89 93 97 99 101 103 107
51 │ 109 113 121 127 131 137 139 143 149 151
61 │ 157 163 167 169 173 179 181 187 191 193
71 │ 197 199
 
Found 72 special divisors N that reverse(D) divides reverse(N) for all divisors D of N, where N < 200
</pre>
 
=={{header|Ring}}==