Special divisors: Difference between revisions
Added Easylang
(Added Forth solution) |
(Added Easylang) |
||
(19 intermediate revisions by 11 users not shown) | |||
Line 6:
=={{header|Action!}}==
<
INT i
Line 55:
FI
OD
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Special_Divisors.png Screenshot from Atari 8-bit computer]
Line 65:
=={{header|ALGOL 68}}==
<
# of n #
# returns n with the digits reversed #
Line 96:
OD;
print( ( newline, "Found ", whole( rd count, 0 ), " ""special divisors"" below 200", newline ) )
END</
{{out}}
<pre>
Line 112:
=={{header|ALGOL W}}==
{{Trans|ALGOL 68}}
<
% of n %
% returns n with the digits reversed %
Line 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 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 168:
=={{header|AppleScript}}==
<
set output to {}
Line 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 234 ⟶ 257:
100 NEXT J
110 PRINT I,
120 NEXT I</
{{out}}
<pre> 1 2 3 4 5
Line 251 ⟶ 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 284 ⟶ 337:
$)
wrch('*N')
$)</
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 11
Line 297 ⟶ 350:
=={{header|C}}==
{{trans|Delphi}}
<
#include <stdio.h>
Line 346 ⟶ 399:
return 0;
}</
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 11
Line 360 ⟶ 413:
=={{header|C++}}==
<
#include <iomanip>
#include <vector>
Line 398 ⟶ 451:
std::cout << std::endl;
return 0;
}</
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 11
Line 411 ⟶ 464:
=={{header|C#}}==
{{trans|C}}
<
namespace SpecialDivisors {
Line 461 ⟶ 514:
}
}
}</
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 11
Line 473 ⟶ 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 532 ⟶ 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 608 ⟶ 705:
=={{header|Cowgol}}==
<
const MAXIMUM := 200;
Line 641 ⟶ 738:
end if;
n := n + 1;
end loop;</
{{out}}
<pre style='height:50ex;'>1
Line 716 ⟶ 813:
{{libheader| System.StrUtils}}
{{Trans|Ring}}
<
{$IFDEF FPC}
{$MODE DELPHI}
Line 780 ⟶ 877:
Main;
{$IFNDEF UNIX} readln; {$ENDIF}
end.</
{{out}}
<pre>Working...
Line 795 ⟶ 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 807 ⟶ 934:
[ reverse-number divisor? ] with all? ;
200 [1..b] [ special? ] filter 18 group simple-table.</
{{out}}
<pre>
Line 818 ⟶ 945:
=={{header|Forth}}==
{{works with|Gforth}}
<
0 >r
begin
Line 862 ⟶ 989:
main
bye</
{{out}}
Line 878 ⟶ 1,005:
=={{header|FreeBASIC}}==
<
dim as integer u = 0
while n
Line 900 ⟶ 1,027:
next d
if s then print using "### ";n;
next n</
=={{header|Go}}==
{{trans|Wren}}
{{libheader|Go-rcu}}
<
import (
Line 945 ⟶ 1,072:
}
fmt.Printf("\n%d special divisors found.\n", len(special))
}</
{{out}}
Line 961 ⟶ 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 968 ⟶ 1,095:
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
<syntaxhighlight lang="jq">
# divisors as an unsorted stream
def divisors:
Line 989 ⟶ 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 1,016 ⟶ 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 1,025 ⟶ 1,152:
=={{header|MAD}}==
<
INTERNAL FUNCTION(X)
Line 1,046 ⟶ 1,173:
CAND CONTINUE
VECTOR VALUES FMT = $I4*$
END OF PROGRAM</
{{out}}
<pre style='height:50ex;'> 1
Line 1,122 ⟶ 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 1,130 ⟶ 1,257:
=={{header|Modula-2}}==
<
FROM InOut IMPORT WriteCard, WriteLn;
Line 1,171 ⟶ 1,298:
END;
WriteLn();
END SpecialDivisors.</
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 11
Line 1,183 ⟶ 1,310:
=={{header|Nim}}==
<
func reversed(n: Positive): int =
Line 1,209 ⟶ 1,336:
break check
inc count
stdout.write ($n).align(3), if count mod 12 == 0: '\n' else: ' '</
{{out}}
Line 1,223 ⟶ 1,350:
=={{header|Perl}}==
{{libheader|ntheory}}
<
use warnings;
use feature 'say';
Line 1,235 ⟶ 1,362:
say @sd . " matching numbers:\n" .
(sprintf "@{['%4d' x @sd]}", @sd) =~ s/(.{40})/$1\n/gr;</
{{out}}
<pre>72 matching numbers:
Line 1,248 ⟶ 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,271 ⟶ 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,282 ⟶ 1,409:
=={{header|PILOT}}==
<
:n=1
*num
Line 1,310 ⟶ 1,437:
:a=b
J (a>0):*revloop
E :</
{{out}}
<pre style='height:50ex;'>1
Line 1,387 ⟶ 1,514:
=={{header|PL/I}}==
<
%replace MAX by 200;
Line 1,418 ⟶ 1,545:
end;
end;
end specialDivisors;</
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 11
Line 1,428 ⟶ 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,499 ⟶ 1,629:
CALL PRINT$NUMBER( MAX$SD + 1 );
CALL PRINT$NL;
EOF</
{{out}}
<pre>
Line 1,512 ⟶ 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,530 ⟶ 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,557 ⟶ 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,576 ⟶ 1,918:
=={{header|Ring}}==
<
load "stdlib.ring"
Line 1,620 ⟶ 1,962:
next
return rev
</syntaxhighlight>
{{out}}
<pre>
Line 1,635 ⟶ 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,644 ⟶ 2,071:
=={{header|Swift}}==
<
func reverse(_ number: Int) -> Int {
Line 1,682 ⟶ 2,109:
}
}
print("\n\(count) numbers found.")</
{{out}}
Line 1,699 ⟶ 2,126:
=={{header|Wren}}==
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<
import "./
var reversed = Fn.new { |n|
Line 1,721 ⟶ 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,738 ⟶ 2,163:
=={{header|XPL0}}==
<
int N, M;
[M:= 0;
Line 1,771 ⟶ 2,196:
IntOut(0, Count);
Text(0, " such numbers found.");
]</
{{out}}
Line 1,785 ⟶ 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,819 ⟶ 2,263:
}
try stdout.print("\n", .{});
}</
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 11
|