Special divisors: Difference between revisions
Content deleted Content added
Not a robot (talk | contribs) Add Modula-2 |
Added Easylang |
||
(23 intermediate revisions by 14 users not shown) | |||
Line 4:
Numbers '''n''' such that reverse('''d''') divides reverse('''n''') for all divisors '''d''' of '''n''', where '''n < 200'''
<br><br>
=={{header|Action!}}==
<syntaxhighlight lang="action!">PROC CalcDivisors(INT x INT ARRAY div INT POINTER count)
INT i
count^=0
FOR i=1 TO x/2
DO
IF x MOD i=0 THEN
div(count^)=i
count^==+1
FI
OD
RETURN
INT FUNC Reverse(INT x)
INT res
res=0
WHILE x#0
DO
res==*10
res==+x MOD 10
x==/10
OD
RETURN (res)
BYTE FUNC IsSpecial(INT x)
INT ARRAY divisors(100)
INT count,i,rev,revd
CalcDivisors(x,divisors,@count)
rev=Reverse(x)
FOR i=0 TO count-1
DO
revd=Reverse(divisors(i))
IF rev MOD revd#0 THEN
RETURN (0)
FI
OD
RETURN (1)
PROC Main()
INT i
FOR i=1 TO 199
DO
IF IsSpecial(i) THEN
PrintI(i) Put(32)
FI
OD
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Special_Divisors.png Screenshot from Atari 8-bit computer]
<pre>
1 2 3 4 5 6 7 8 9 11 13 17 19 22 23 26 27 29 31 33 37 39 41 43 44 46 47 53 55
59 61 62 66 67 69 71 73 77 79 82 83 86 88 89 93 97 99 101 103 107 109 113 121
127 131 137 139 143 149 151 157 163 167 169 173 179 181 187 191 193 197 199
</pre>
=={{header|ALGOL 68}}==
<
# of n #
# returns n with the digits reversed #
Line 37 ⟶ 96:
OD;
print( ( newline, "Found ", whole( rd count, 0 ), " ""special divisors"" below 200", newline ) )
END</
{{out}}
<pre>
Line 53 ⟶ 112:
=={{header|ALGOL W}}==
{{Trans|ALGOL 68}}
<
% of n %
% returns n with the digits reversed %
Line 95 ⟶ 154:
end for_n ;
write( i_w := 1, s_w := 0, "Found ", rdCount, " ""special divisors"" below 200" )
end.</
{{out}}
Same as the Algol 68 sample.
Line 101 ⟶ 160:
=={{header|APL}}==
{{works with|Dyalog APL}}
<
{{out}}
<pre>1 2 3 4 5 6 7 8 9 11 13 17 19 22 23 26 27 29 31 33 37 39 41 43 44 46 47
Line 109 ⟶ 168:
=={{header|AppleScript}}==
<
set output to {}
Line 158 ⟶ 217:
if (hasSpecialDivisors(n, base)) then set end of output to n
end repeat
return {|count|:(count output), finds:output}</
{{output}}
<
=={{header|Arturo}}==
<syntaxhighlight lang="arturo">reversed: function [x]->
to :integer join to [:string] reverse digits x
specialDivisors: select 1..200 'n ->
every? factors n 'd ->
zero? (reversed n) % reversed d
loop split.every: 9 specialDivisors 'x ->
print map x 's -> pad to :string s 4</syntaxhighlight>
{{out}}
<pre> 1 2 3 4 5 6 7 8 9
11 13 17 19 22 23 26 27 29
31 33 37 39 41 43 44 46 47
53 55 59 61 62 66 67 69 71
73 77 79 82 83 86 88 89 93
97 99 101 103 107 109 113 121 127
131 137 139 143 149 151 157 163 167
169 173 179 181 187 191 193 197 199</pre>
=={{header|BASIC}}==
<
20 FOR I=1 TO 199
30 J=I: X=0
Line 175 ⟶ 257:
100 NEXT J
110 PRINT I,
120 NEXT I</
{{out}}
<pre> 1 2 3 4 5
Line 192 ⟶ 274:
179 181 187 191 193
197 199</pre>
=={{header|BASIC256}}==
<syntaxhighlight lang="freebasic">c = 0
for n = 1 to 200
u = reverse(n)
s = true
for d = 1 to n
if n mod d = 0 then
b = reverse(d)
if u mod b <> 0 then s = false
end if
next d
if s then c += 1 : print n; chr(9);
next n
print
print "Found "; c; " special divisors."
end
function reverse(n)
u = 0
while n
u = u * 10 + n mod 10
n = n \ 10
end while
return u
end function</syntaxhighlight>
{{out}}
<pre>1 2 3 4 5 6 7 8 9 11 13 17 19 22 23 26 27 29 31 33 37 39 41 43 44 46 47 53 55 59 61 62 66 67 69 71 73 77 79 82 83 86 88 89 93 97 99 101 103 107 109 113 121 127 131 137 139 143 149 151 157 163 167 169 173 179 181 187 191 193 197 199
Found 72 special divisors.</pre>
=={{header|BCPL}}==
<
let reverse(n) = valof
Line 225 ⟶ 337:
$)
wrch('*N')
$)</
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 11
Line 238 ⟶ 350:
=={{header|C}}==
{{trans|Delphi}}
<
#include <stdio.h>
Line 287 ⟶ 399:
return 0;
}</
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 11
Line 301 ⟶ 413:
=={{header|C++}}==
<
#include <iomanip>
#include <vector>
Line 339 ⟶ 451:
std::cout << std::endl;
return 0;
}</
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 11
Line 352 ⟶ 464:
=={{header|C#}}==
{{trans|C}}
<
namespace SpecialDivisors {
Line 402 ⟶ 514:
}
}
}</
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 11
Line 414 ⟶ 526:
Found 72 special divisors N that reverse(D) divides reverse(N) for all divisors D of N, where N < 200</pre>
=={{header|CLU}}==
<syntaxhighlight lang="clu">reverse = proc (n: int) returns (int)
r: int := 0
while n>0 do
r := r*10 + n//10
n := n/10
end
return(r)
end reverse
special = proc (n: int) returns (bool)
r: int := reverse(n)
for d: int in int$from_to(1,n/2) do
if n//d=0 & r//reverse(d)~=0 then
return(false)
end
end
return(true)
end special
start_up = proc ()
po: stream := stream$primary_output()
c: int := 0
for n: int in int$from_to(1,199) do
if special(n) then
stream$putright(po, int$unparse(n), 4)
c := c+1
if c=10 then
stream$putl(po, "")
c := 0
end
end
end
end start_up</syntaxhighlight>
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 11
13 17 19 22 23 26 27 29 31 33
37 39 41 43 44 46 47 53 55 59
61 62 66 67 69 71 73 77 79 82
83 86 88 89 93 97 99 101 103 107
109 113 121 127 131 137 139 143 149 151
157 163 167 169 173 179 181 187 191 193
197 199</pre>
=={{header|COBOL}}==
<
PROGRAM-ID. SPECIAL-DIVISORS.
Line 473 ⟶ 629:
MOVE REV-DIGITS(RD) TO TEMP.
MOVE REV-DIGITS(3) TO REV-DIGITS(RD).
MOVE TEMP TO REV-DIGITS(3).</
{{out}}
<pre style='height:50ex;'> 1
Line 549 ⟶ 705:
=={{header|Cowgol}}==
<
const MAXIMUM := 200;
Line 582 ⟶ 738:
end if;
n := n + 1;
end loop;</
{{out}}
<pre style='height:50ex;'>1
Line 657 ⟶ 813:
{{libheader| System.StrUtils}}
{{Trans|Ring}}
<
{$IFDEF FPC}
{$MODE DELPHI}
Line 721 ⟶ 877:
Main;
{$IFNDEF UNIX} readln; {$ENDIF}
end.</
{{out}}
<pre>Working...
Line 736 ⟶ 892:
Found 72 special divisors N that reverse(D) divides reverse(N) for all divisors D of N, where N < 200
Done...</pre>
=={{header|EasyLang}}==
{{trans|Python}}
<syntaxhighlight>
func reverse s .
while s > 0
e = e * 10 + s mod 10
s = s div 10
.
return e
.
for n = 1 to 199
u = reverse n
for d = 1 to n - 1
if n mod d = 0
b = reverse d
if u mod b <> 0
break 1
.
.
.
if d = n
write n & " "
.
.
</syntaxhighlight>
{{out}}
<pre>
1 2 3 4 5 6 7 8 9 11 13 17 19 22 23 26 27 29 31 33 37 39 41 43 44 46 47 53 55 59 61 62 66 67 69 71 73 77 79 82 83 86 88 89 93 97 99 101 103 107 109 113 121 127 131 137 139 143 149 151 157 163 167 169 173 179 181 187 191 193 197 199
</pre>
=={{header|Factor}}==
{{works with|Factor|0.99 2021-02-05}}
<
math.primes.factors math.ranges prettyprint sequences ;
Line 748 ⟶ 934:
[ reverse-number divisor? ] with all? ;
200 [1..b] [ special? ] filter 18 group simple-table.</
{{out}}
<pre>
Line 756 ⟶ 942:
131 137 139 143 149 151 157 163 167 169 173 179 181 187 191 193 197 199
</pre>
=={{header|Forth}}==
{{works with|Gforth}}
<syntaxhighlight lang="forth">: reverse ( n -- n )
0 >r
begin
dup 0 >
while
10 /mod swap
r> 10 * + >r
repeat
drop r> ;
: special? ( n -- ? )
dup reverse >r
2
begin
2dup dup * >=
while
2dup mod 0= if
dup reverse r@ swap mod 0 <> if
rdrop 2drop false exit
then
2dup / dup 2 pick <> if
reverse r@ swap mod 0 <> if
rdrop 2drop false exit
then
else
drop
then
then
1+
repeat
rdrop 2drop true ;
: main
0
200 1 do
i special? if
i 3 .r
1+
dup 10 mod 0= if cr else space then
then
loop cr
. ." numbers found." cr ;
main
bye</syntaxhighlight>
{{out}}
<pre>
1 2 3 4 5 6 7 8 9 11
13 17 19 22 23 26 27 29 31 33
37 39 41 43 44 46 47 53 55 59
61 62 66 67 69 71 73 77 79 82
83 86 88 89 93 97 99 101 103 107
109 113 121 127 131 137 139 143 149 151
157 163 167 169 173 179 181 187 191 193
197 199
72 numbers found.
</pre>
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">function reverse(n as integer) as integer
dim as integer u = 0
while n
u = 10*u + n mod 10
n\=10
wend
return u
end function
dim as integer n, u, d, b
dim as boolean s
for n = 1 to 200
u = reverse(n)
s = true
for d = 1 to n
if n mod d = 0 then
b = reverse(d)
if u mod b <> 0 then s = false
end if
next d
if s then print using "### ";n;
next n</syntaxhighlight>
=={{header|Go}}==
{{trans|Wren}}
{{libheader|Go-rcu}}
<
import (
Line 800 ⟶ 1,072:
}
fmt.Printf("\n%d special divisors found.\n", len(special))
}</
{{out}}
Line 816 ⟶ 1,088:
=={{header|J}}==
<
{{out}}
<pre>1 2 3 4 5 6 7 8 9 11 13 17 19 22 23 26 27 29 31 33 37 39 41 43 44 46 47 53 55 59 61 62 66 67 69 71 73 77 79 82 83 86 88 89 93 97 99 101 103 107 109 113 121 127 131 137 139 143 149 151 157 163 167 169 173 179 181 187 191 193 197 199</pre>
Line 823 ⟶ 1,095:
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
<syntaxhighlight lang="jq">
# divisors as an unsorted stream
def divisors:
Line 844 ⟶ 1,116:
| all(divisors; $nreverse % reverse_number == 0);
range(1;200) | select(is_special_divisor)</
{{out}}
A stream of numbers as shown elsewhere on this page.
=={{header|Julia}}==
<
function divisors(n)
Line 871 ⟶ 1,143:
const specials = filter(isspecialdivisor, 1:200)
foreach(p -> print(rpad(p[2], 4), p[1] % 18 == 0 ? "\n" : ""), enumerate(specials))
</
<pre>
1 2 3 4 5 6 7 8 9 11 13 17 19 22 23 26 27 29
Line 880 ⟶ 1,152:
=={{header|MAD}}==
<
INTERNAL FUNCTION(X)
Line 901 ⟶ 1,173:
CAND CONTINUE
VECTOR VALUES FMT = $I4*$
END OF PROGRAM</
{{out}}
<pre style='height:50ex;'> 1
Line 977 ⟶ 1,249:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
Select[Range[199], SpecialDivisorQ]
Length[%]</
{{out}}
<pre>{1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13, 17, 19, 22, 23, 26, 27, 29, 31, 33, 37, 39, 41, 43, 44, 46, 47, 53, 55, 59, 61, 62, 66, 67, 69, 71, 73, 77, 79, 82, 83, 86, 88, 89, 93, 97, 99, 101, 103, 107, 109, 113, 121, 127, 131, 137, 139, 143, 149, 151, 157, 163, 167, 169, 173, 179, 181, 187, 191, 193, 197, 199}
Line 985 ⟶ 1,257:
=={{header|Modula-2}}==
<
FROM InOut IMPORT WriteCard, WriteLn;
Line 1,026 ⟶ 1,298:
END;
WriteLn();
END SpecialDivisors.</
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 11
Line 1,038 ⟶ 1,310:
=={{header|Nim}}==
<
func reversed(n: Positive): int =
Line 1,064 ⟶ 1,336:
break check
inc count
stdout.write ($n).align(3), if count mod 12 == 0: '\n' else: ' '</
{{out}}
Line 1,078 ⟶ 1,350:
=={{header|Perl}}==
{{libheader|ntheory}}
<
use warnings;
use feature 'say';
Line 1,090 ⟶ 1,362:
say @sd . " matching numbers:\n" .
(sprintf "@{['%4d' x @sd]}", @sd) =~ s/(.{40})/$1\n/gr;</
{{out}}
<pre>72 matching numbers:
Line 1,103 ⟶ 1,375:
=={{header|Phix}}==
<!--<
<span style="color: #008080;">function</span> <span style="color: #000000;">rev</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">r</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span>
Line 1,126 ⟶ 1,398:
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</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;">"%3d"</span><span style="color: #0000FF;">},</span><span style="color: #7060A8;">filter</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">200</span><span style="color: #0000FF;">),</span><span style="color: #000000;">special_divisors</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;">"Found %d special divisors:\n%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_by</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">18</span><span style="color: #0000FF;">)})</span>
<!--</
{{out}}
<pre>
Line 1,135 ⟶ 1,407:
131 137 139 143 149 151 157 163 167 169 173 179 181 187 191 193 197 199
</pre>
=={{header|PILOT}}==
<syntaxhighlight lang="pilot">C :max=200
:n=1
*num
C :x=n
U :*rev
C :rn=r
:d=1
*div
J (d*(n/d)<>n):*nextdiv
C :x=d
U :*rev
J (r*(rn/r)<>rn):*next
*nextdiv
C :d=d+1
J (d<=n/2):*div
T :#n
*next
C :n=n+1
J (n<max):*num
E :
*rev
C :r=0
:a=x
*revloop
C :b=a/10
:r=r+(a-b*10)
:a=b
J (a>0):*revloop
E :</syntaxhighlight>
{{out}}
<pre style='height:50ex;'>1
2
3
4
5
6
7
8
9
11
13
17
19
22
23
26
27
29
31
33
37
39
41
43
44
46
47
53
55
59
61
62
66
67
69
71
73
77
79
81
82
83
86
88
89
93
97
99
101
103
107
109
113
121
127
131
137
139
143
149
151
157
163
167
169
173
179
181
187
191
193
197
199</pre>
=={{header|PL/I}}==
<
%replace MAX by 200;
Line 1,168 ⟶ 1,545:
end;
end;
end specialDivisors;</
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 11
Line 1,178 ⟶ 1,555:
157 163 167 169 173 179 181 187 191 193
197 199</pre>
See also [[#Polyglot:PL/I and PL/M]]
=={{header|PL/M}}==
{{works with|8080 PL/M Compiler}} ... under CP/M (or an emulator)
<syntaxhighlight lang="pli">100H: /* FIND NUMBERS WHOSE REVERSED DIVISORS DIVIDE THE REVERSED NUMBER */
DECLARE TRUE LITERALLY '0FFH';
Line 1,249 ⟶ 1,629:
CALL PRINT$NUMBER( MAX$SD + 1 );
CALL PRINT$NL;
EOF</
{{out}}
<pre>
Line 1,262 ⟶ 1,642:
FOUND 72 ''SPECIAL DIVISORS'' BELOW 200
</pre>
See also [[#Polyglot:PL/I and PL/M]]
=={{header|Polyglot:PL/I and PL/M}}==
{{works with|8080 PL/M Compiler}} ... under CP/M (or an emulator)
Should work with many PL/I implementations.<br>
The PL/I include file "pg.inc" can be found on the [[Polyglot:PL/I and PL/M]] page.
Note the use of text in column 81 onwards to hide the PL/I specifics from the PL/M compiler.
<syntaxhighlight lang="pli">/* FIND NUMBERS WHOSE REVERSED DIVISORS DIVIDE THE REVERSED NUMBER */
special_divisors_100H: procedure options (main);
/* PL/I DEFINITIONS */
%include 'pg.inc';
/* PL/M DEFINITIONS: CP/M BDOS SYSTEM CALL AND CONSOLE I/O ROUTINES, ETC. */ /*
DECLARE BINARY LITERALLY 'ADDRESS', CHARACTER LITERALLY 'BYTE';
DECLARE SADDR LITERALLY '.', BIT LITERALLY 'BYTE';
DECLARE TRUE LITERALLY '1', FALSE LITERALLY '0';
BDOSF: PROCEDURE( FN, ARG )BYTE;
DECLARE FN BYTE, ARG ADDRESS; GOTO 5; END;
BDOS: PROCEDURE( FN, ARG ); DECLARE FN BYTE, ARG ADDRESS; GOTO 5; END;
PRSTRING: PROCEDURE( S ); DECLARE S ADDRESS; CALL BDOS( 9, S ); END;
PRCHAR: PROCEDURE( C ); DECLARE C CHARACTER; CALL BDOS( 2, C ); END;
PRNL: PROCEDURE; CALL PRCHAR( 0DH ); CALL PRCHAR( 0AH ); END;
PRNUMBER: PROCEDURE( N );
DECLARE N ADDRESS;
DECLARE V ADDRESS, N$STR( 6 ) BYTE, W BYTE;
N$STR( W := LAST( N$STR ) ) = '$';
N$STR( W := W - 1 ) = '0' + ( ( V := N ) MOD 10 );
DO WHILE( ( V := V / 10 ) > 0 );
N$STR( W := W - 1 ) = '0' + ( V MOD 10 );
END;
CALL BDOS( 9, .N$STR( W ) );
END PRNUMBER;
MODF: PROCEDURE( A, B )ADDRESS;
DECLARE ( A, B )ADDRESS;
RETURN( A MOD B );
END MODF;
/* END LANGUAGE DEFINITIONS */
/* TASK */
REVERSE: PROCEDURE( N )returns (
BINARY )
; /* RETURNS THE REVERSED DIGITS OF N */
DECLARE N BINARY;
DECLARE ( R, V ) BINARY;
V = N;
R = MODF( V, 10 );
V = V / 10;
DO WHILE( V > 0 );
R = ( R * 10 ) + MODF( V, 10 );
V = V / 10;
END;
RETURN ( R );
END REVERSE ;
/* FIND AND SHOW THE NUMBERS UP TO 200 */
DECLARE ( N, RN, SDCOUNT, D, DMAX ) BINARY;
DECLARE ISSD BIT;
DECLARE MAXSD BINARY static INITIAL( 199 );
SDCOUNT = 0;
DO N = 1 TO MAXSD;
RN = REVERSE( N );
ISSD = TRUE;
D = 2; DMAX = N / 2;
DO WHILE( ISSD & /*
AND /* */ D < DMAX );
IF MODF( N, D ) = 0 THEN DO;
/* HAVE A DIVISOR OF N */
ISSD = ( MODF( RN, REVERSE( D ) ) = 0 );
END;
D = D + 1;
END;
IF ISSD THEN DO;
/* ALL THE REVERSED DIVISORS OF N DIVIDE N REVERSED */
CALL PRCHAR( ' ' );
IF N < 100 THEN DO;
CALL PRCHAR( ' ' );
IF N < 10 THEN CALL PRCHAR( ' ' );
END;
CALL PRNUMBER( N );
SDCOUNT = SDCOUNT + 1;
IF MODF( SDCOUNT, 10 ) = 0 THEN CALL PRNL;
END;
END;
CALL PRNL;
CALL PRSTRING( SADDR( 'FOUND $' ) );
CALL PRNUMBER( SDCOUNT );
CALL PRSTRING( SADDR( ' ''''SPECIAL DIVISORS'''' BELOW $' ) );
CALL PRNUMBER( MAXSD + 1 );
CALL PRNL;
EOF: end special_divisors_100H;</syntaxhighlight>
{{out}}
<pre>
1 2 3 4 5 6 7 8 9 11
13 17 19 22 23 26 27 29 31 33
37 39 41 43 44 46 47 53 55 59
61 62 66 67 69 71 73 77 79 82
83 86 88 89 93 97 99 101 103 107
109 113 121 127 131 137 139 143 149 151
157 163 167 169 173 179 181 187 191 193
197 199
FOUND 72 ''SPECIAL DIVISORS'' BELOW 200
</pre>
=={{header|PureBasic}}==
<syntaxhighlight lang="purebasic">Procedure reverse(n.i)
u.i = 0
While n
u = u * 10 + (n % 10)
n = Int(n / 10)
Wend
ProcedureReturn u
EndProcedure
OpenConsole()
c.i = 0
For n.i = 1 To 200
u.i = reverse(n)
s.b = #True
For d.i = 1 To n
If n % d = 0
b = reverse(d)
If u % b <> 0
s = #False
EndIf
EndIf
Next d
If s
Print(Str(n) + #TAB$)
c + 1
EndIf
Next n
PrintN(#CRLF$ + "Found " + Str(c) + " special divisors.")
Input()
CloseConsole()</syntaxhighlight>
{{out}}
<pre>1 2 3 4 5 6 7 8 9 11 13 17 19 22 23
26 27 29 31 33 37 39 41 43 44 46 47 53 55
59 61 62 66 67 69 71 73 77 79 82 83 86 88
89 93 97 99 101 103 107 109 113 121 127 131 137 139
143 149 151 157 163 167 169 173 179 181 187 191 193 197
199
Found 72 special divisors.</pre>
=={{header|Python}}==
<syntaxhighlight lang="python">#!/usr/bin/python
def reverse(n):
u = 0
while n:
u = 10 * u + n % 10
n = int(n / 10)
return u
c = 0
for n in range(1, 200):
u = reverse(n)
s = True
for d in range (1, n):
if n % d == 0:
b = reverse(d)
if u % b != 0:
s = False
if s:
c = c + 1
print(n, end='\t')
print("\nEncontrados ", c, "divisores especiales.")</syntaxhighlight>
{{out}}
<pre>1 2 3 4 5 6 7 8 9 11 13 17 19 22 23 26 27 29 31 33 37 39 41 43 44 46 47 53 55 59 61 62 66 67 69 71 73 77 79 82 83 86 88 89 93 97 99 101 103 107 109 113 121 127 131 137 139 143 149 151 157 163 167 169 173 179 181 187 191 193 197 199
Encontrados 72 divisores especiales.</pre>
=={{header|Quackery}}==
<code>factors</code> is defined at [[Factors of an integer#Quackery]].
<syntaxhighlight lang="Quackery"> [ 0
[ swap 10 /mod
rot 10 * +
over 0 = until ]
nip ] is revnum ( n --> n )
[]
[ 200 times
[ true
i^ revnum
i^ factors
witheach
[ revnum
dip dup mod
0 != if
[ dip not
conclude ] ]
drop
if [ i^ join ] ]
behead drop ]
[]
swap witheach
[ number$ nested join ]
48 wrap$</syntaxhighlight>
{{out}}
<pre>1 2 3 4 5 6 7 8 9 11 13 17 19 22 23 26 27 29 31
33 37 39 41 43 44 46 47 53 55 59 61 62 66 67 69
71 73 77 79 82 83 86 88 89 93 97 99 101 103 107
109 113 121 127 131 137 139 143 149 151 157 163
167 169 173 179 181 187 191 193 197 199</pre>
=={{header|Raku}}==
<syntaxhighlight lang="raku"
say "{+$_} matching numbers:\n{.batch(10)».fmt('%3d').join: "\n"}"
given (1..^200).grep: { all .flip «%%« .&divisors».flip };</
{{out}}
<pre>72 matching numbers:
Line 1,280 ⟶ 1,872:
=={{header|REXX}}==
<
/*────────────────────────── reverse(N) for all divisors D of N, where N < 200. */
parse arg hi cols . /*obtain optional argument from the CL.*/
Line 1,307 ⟶ 1,899:
if cols>0 then say '───────┴'center("" , 1 + cols*(w+1), '─')
say
say 'Found ' found title</
{{out|output|text= when using the default inputs:}}
<pre>
Line 1,326 ⟶ 1,918:
=={{header|Ring}}==
<
load "stdlib.ring"
Line 1,370 ⟶ 1,962:
next
return rev
</syntaxhighlight>
{{out}}
<pre>
Line 1,385 ⟶ 1,977:
done...
</pre>
=={{header|RPL}}==
{{works with|HP|49}}
≪ →STR ""
OVER SIZE 1 '''FOR''' j
OVER j DUP SUB +
-1 '''STEP'''
STR→ NIP
≫ '<span style="color:blue">REVNUM</span>' STO
≪ {1}
2 200 FOR n
1 SF
n <span style="color:blue">REVNUM</span> n DIVIS
2 OVER SIZE 1 - '''FOR''' d
'''IF''' DUP2 d GET <span style="color:blue">REVNUM</span> MOD '''THEN'''
1 CF DUP SIZE 'd' STO '''END'''
'''NEXT''' DROP2
'''IF''' 1 FS? '''THEN''' n + '''END'''
'''NEXT'''
≫ '<span style="color:blue">TASK</span>' STO
{{out}}
<pre>
1: {1 2 3 4 5 6 7 8 9 11 13 17 19 22 23 26 27 29 31 33 37 39 41 43 44 46 47 53 55 59 61 62 66 67 69 71 73 77 79 82 83 86 88 89 93 97 99 101 103 107 109 113 121 127 131 137 139 143 149 151 157 163 167 169 173 179 181 187 191 193 197 199}
</pre>
Runs in 62 seconds on a HP-50g.
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">class Integer
def reverse
to_s.reverse.to_i
end
def divisors
res = []
(1..Integer.sqrt(self)).each do |cand|
div, mod = self.divmod(cand)
res << cand << div if mod == 0
end
res.uniq.sort
end
def special_divisors?
r = self.reverse
divisors.all?{|d| r % d.reverse == 0}
end
end
p (1..200).select(&:special_divisors?)</syntaxhighlight>
{{out}}
<pre>
[1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13, 17, 19, 22, 23, 26, 27, 29, 31, 33, 37, 39, 41, 43, 44, 46, 47, 53, 55, 59, 61, 62, 66, 67, 69, 71, 73, 77, 79, 82, 83, 86, 88, 89, 93, 97, 99, 101, 103, 107, 109, 113, 121, 127, 131, 137, 139, 143, 149, 151, 157, 163, 167, 169, 173, 179, 181, 187, 191, 193, 197, 199]
</pre>
=={{header|Rust}}==
<syntaxhighlight lang="rust">fn condition( num : u16 ) -> bool {
let divis : Vec<u16> = divisors( num ) ;
let reversed : u16 = my_reverse( num ) ;
divis.iter( ).all( | d | {
let revi = my_reverse( *d ) ;
reversed % revi == 0 } )
}
fn my_reverse( num : u16 ) -> u16 {
let numstring : String = num.to_string( ) ;
let nstr : &str = numstring.as_str( ) ;
let mut reversed_str : String = String::new( ) ;
for c in nstr.chars( ).rev( ) {
reversed_str.push( c ) ;
}
let reversi : &str = reversed_str.as_str( ) ;
reversi.parse::<u16>( ).unwrap( )
}
fn divisors( n : u16 ) -> Vec<u16> {
(1..=n).filter( | &d | n % d == 0 ).collect( )
}
fn main() {
println!("{:?}" , (1u16..200u16).filter( | &d | condition( d ) ).collect
::<Vec<u16>>( ) ) ;
}</syntaxhighlight>
{{out}}
<pre>
[1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13, 17, 19, 22, 23, 26, 27, 29, 31, 33, 37, 39, 41, 43, 44, 46, 47, 53, 55, 59, 61, 62, 66, 67, 69, 71, 73, 77, 79, 82, 83, 86, 88, 89, 93, 97, 99, 101, 103, 107, 109, 113, 121, 127, 131, 137, 139, 143, 149, 151, 157, 163, 167, 169, 173, 179, 181, 187, 191, 193, 197, 199]
</pre>
=={{header|Sidef}}==
<
{{out}}
<pre>
Line 1,394 ⟶ 2,071:
=={{header|Swift}}==
<
func reverse(_ number: Int) -> Int {
Line 1,432 ⟶ 2,109:
}
}
print("\n\(count) numbers found.")</
{{out}}
Line 1,449 ⟶ 2,126:
=={{header|Wren}}==
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<
import "./
var reversed = Fn.new { |n|
Line 1,471 ⟶ 2,146:
}
System.print("Special divisors in the range 0..199:")
Fmt.tprint("$3d", special, 12)
System.print("\n%(special.count) special divisors found.")</
{{out}}
Line 1,488 ⟶ 2,163:
=={{header|XPL0}}==
<
int N, M;
[M:= 0;
Line 1,521 ⟶ 2,196:
IntOut(0, Count);
Text(0, " such numbers found.");
]</
{{out}}
Line 1,535 ⟶ 2,210:
72 such numbers found.
</pre>
=={{header|Yabasic}}==
{{trans|BASIC}}
<syntaxhighlight lang="yabasic">// Rosetta Code problem: http://rosettacode.org/wiki/Special_divisors
// by Galileo, 04/2022
20 FOR I=1 TO 199
30 J=I: X=0
40 IF J>0 X=X*10+MOD(J, 10): J=INT(J/10): GOTO 40
50 FOR J=1 TO INT(I/2)
60 IF MOD(I, J) GOTO 100
70 K=J: Y=0
80 IF K>0 Y=Y*10+MOD(K, 10): K=INT(K/10): GOTO 80
90 IF MOD(X, Y) GOTO 120
100 NEXT J
110 PRINT I,
120 NEXT I</syntaxhighlight>
{{out}}
<pre>1 2 3 4 5 6 7 8 9 11 13 17 19 22 23 26 27 29 31 33 37 39 41 43 44 46 47 53 55 59 61 62 66 67 69 71 73 77 79 82 83 86 88 89 93 97 99 101 103 107 109 113 121 127 131 137 139 143 149 151 157 163 167 169 173 179 181 187 191 193 197 199 ---Program done, press RETURN---</pre>
=={{header|Zig}}==
<
const N = u16; // smallest integer type that fits
Line 1,569 ⟶ 2,263:
}
try stdout.print("\n", .{});
}</
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 11
|