Special divisors: Difference between revisions

no edit summary
(Add CLU)
No edit summary
(17 intermediate revisions by 9 users not shown)
Line 6:
 
=={{header|Action!}}==
<langsyntaxhighlight Actionlang="action!">PROC CalcDivisors(INT x INT ARRAY div INT POINTER count)
INT i
 
Line 55:
FI
OD
RETURN</langsyntaxhighlight>
{{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}}==
<langsyntaxhighlight lang="algol68">BEGIN # find numbers where reverse(d) divides reverse(n) for all divisors d #
# of n #
# returns n with the digits reversed #
Line 96:
OD;
print( ( newline, "Found ", whole( rd count, 0 ), " ""special divisors"" below 200", newline ) )
END</langsyntaxhighlight>
{{out}}
<pre>
Line 112:
=={{header|ALGOL W}}==
{{Trans|ALGOL 68}}
<langsyntaxhighlight lang="algolw">begin % find numbers where reverse(d) divides reverse(n) for all divisors d %
% 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.</langsyntaxhighlight>
{{out}}
Same as the Algol 68 sample.
Line 160:
=={{header|APL}}==
{{works with|Dyalog APL}}
<langsyntaxhighlight APLlang="apl">(⊢(/⍨)(0∧.=(⍎⌽∘⍕)¨∘(⍸0=⍳|⊢)|(⍎⌽∘⍕))¨) ⍳200</langsyntaxhighlight>
{{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}}==
<langsyntaxhighlight lang="applescript">on factors(n)
set output to {}
Line 217:
if (hasSpecialDivisors(n, base)) then set end of output to n
end repeat
return {|count|:(count output), finds:output}</langsyntaxhighlight>
 
{{output}}
<langsyntaxhighlight lang="applescript">{|count|:72, finds:{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}}</langsyntaxhighlight>
 
=={{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}}==
<langsyntaxhighlight BASIClang="basic">10 DEFINT A-Z
20 FOR I=1 TO 199
30 J=I: X=0
Line 234 ⟶ 257:
100 NEXT J
110 PRINT I,
120 NEXT I</langsyntaxhighlight>
{{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}}==
<langsyntaxhighlight BCPLlang="bcpl">get "libhdr"
 
let reverse(n) = valof
Line 284 ⟶ 337:
$)
wrch('*N')
$)</langsyntaxhighlight>
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 11
Line 297 ⟶ 350:
=={{header|C}}==
{{trans|Delphi}}
<langsyntaxhighlight lang="c">#include <stdbool.h>
#include <stdio.h>
 
Line 346 ⟶ 399:
 
return 0;
}</langsyntaxhighlight>
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 11
Line 360 ⟶ 413:
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <iostream>
#include <iomanip>
#include <vector>
Line 398 ⟶ 451:
std::cout << std::endl;
return 0;
}</langsyntaxhighlight>
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 11
Line 411 ⟶ 464:
=={{header|C#}}==
{{trans|C}}
<langsyntaxhighlight lang="csharp">using System;
 
namespace SpecialDivisors {
Line 461 ⟶ 514:
}
}
}</langsyntaxhighlight>
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 11
Line 475 ⟶ 528:
 
=={{header|CLU}}==
<langsyntaxhighlight lang="clu">reverse = proc (n: int) returns (int)
r: int := 0
while n>0 do
Line 507 ⟶ 560:
end
end
end start_up</langsyntaxhighlight>
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 11
Line 519 ⟶ 572:
 
=={{header|COBOL}}==
<langsyntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. SPECIAL-DIVISORS.
Line 576 ⟶ 629:
MOVE REV-DIGITS(RD) TO TEMP.
MOVE REV-DIGITS(3) TO REV-DIGITS(RD).
MOVE TEMP TO REV-DIGITS(3).</langsyntaxhighlight>
{{out}}
<pre style='height:50ex;'> 1
Line 652 ⟶ 705:
 
=={{header|Cowgol}}==
<langsyntaxhighlight lang="cowgol">include "cowgol.coh";
 
const MAXIMUM := 200;
Line 685 ⟶ 738:
end if;
n := n + 1;
end loop;</langsyntaxhighlight>
{{out}}
<pre style='height:50ex;'>1
Line 760 ⟶ 813:
{{libheader| System.StrUtils}}
{{Trans|Ring}}
<langsyntaxhighlight Delphilang="delphi">program Special_Divisors;
{$IFDEF FPC}
{$MODE DELPHI}
Line 824 ⟶ 877:
Main;
{$IFNDEF UNIX} readln; {$ENDIF}
end.</langsyntaxhighlight>
{{out}}
<pre>Working...
Line 842 ⟶ 895:
=={{header|Factor}}==
{{works with|Factor|0.99 2021-02-05}}
<langsyntaxhighlight lang="factor">USING: grouping kernel math.functions math.parser
math.primes.factors math.ranges prettyprint sequences ;
 
Line 851 ⟶ 904:
[ reverse-number divisor? ] with all? ;
 
200 [1..b] [ special? ] filter 18 group simple-table.</langsyntaxhighlight>
{{out}}
<pre>
Line 862 ⟶ 915:
=={{header|Forth}}==
{{works with|Gforth}}
<langsyntaxhighlight lang="forth">: reverse ( n -- n )
0 >r
begin
Line 906 ⟶ 959:
 
main
bye</langsyntaxhighlight>
 
{{out}}
Line 922 ⟶ 975:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">function reverse(n as integer) as integer
dim as integer u = 0
while n
Line 944 ⟶ 997:
next d
if s then print using "### ";n;
next n</langsyntaxhighlight>
 
=={{header|Go}}==
{{trans|Wren}}
{{libheader|Go-rcu}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 989 ⟶ 1,042:
}
fmt.Printf("\n%d special divisors found.\n", len(special))
}</langsyntaxhighlight>
 
{{out}}
Line 1,005 ⟶ 1,058:
 
=={{header|J}}==
<langsyntaxhighlight Jlang="j">([#~([:*./0=|.&.":"0@>:@I.@(0=>:@i.|])||.&.":)"0)>:i.200</langsyntaxhighlight>
{{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 1,012 ⟶ 1,065:
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
<syntaxhighlight lang="jq">
<lang jq>
# divisors as an unsorted stream
def divisors:
Line 1,033 ⟶ 1,086:
| all(divisors; $nreverse % reverse_number == 0);
 
range(1;200) | select(is_special_divisor)</langsyntaxhighlight>
{{out}}
A stream of numbers as shown elsewhere on this page.
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">using Primes
 
function divisors(n)
Line 1,060 ⟶ 1,113:
const specials = filter(isspecialdivisor, 1:200)
foreach(p -> print(rpad(p[2], 4), p[1] % 18 == 0 ? "\n" : ""), enumerate(specials))
</langsyntaxhighlight>{{out}}
<pre>
1 2 3 4 5 6 7 8 9 11 13 17 19 22 23 26 27 29
Line 1,069 ⟶ 1,122:
 
=={{header|MAD}}==
<langsyntaxhighlight MADlang="mad"> NORMAL MODE IS INTEGER
INTERNAL FUNCTION(X)
Line 1,090 ⟶ 1,143:
CAND CONTINUE
VECTOR VALUES FMT = $I4*$
END OF PROGRAM</langsyntaxhighlight>
{{out}}
<pre style='height:50ex;'> 1
Line 1,166 ⟶ 1,219:
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">SpecialDivisorQ[n_Integer] := AllTrue[Divisors[n], Divisible[IntegerReverse[n], IntegerReverse[#]] &]
Select[Range[199], SpecialDivisorQ]
Length[%]</langsyntaxhighlight>
{{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,174 ⟶ 1,227:
 
=={{header|Modula-2}}==
<langsyntaxhighlight lang="modula2">MODULE SpecialDivisors;
FROM InOut IMPORT WriteCard, WriteLn;
 
Line 1,215 ⟶ 1,268:
END;
WriteLn();
END SpecialDivisors.</langsyntaxhighlight>
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 11
Line 1,227 ⟶ 1,280:
 
=={{header|Nim}}==
<langsyntaxhighlight Nimlang="nim">import strutils
 
func reversed(n: Positive): int =
Line 1,253 ⟶ 1,306:
break check
inc count
stdout.write ($n).align(3), if count mod 12 == 0: '\n' else: ' '</langsyntaxhighlight>
 
{{out}}
Line 1,267 ⟶ 1,320:
=={{header|Perl}}==
{{libheader|ntheory}}
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use feature 'say';
Line 1,279 ⟶ 1,332:
 
say @sd . " matching numbers:\n" .
(sprintf "@{['%4d' x @sd]}", @sd) =~ s/(.{40})/$1\n/gr;</langsyntaxhighlight>
{{out}}
<pre>72 matching numbers:
Line 1,292 ⟶ 1,345:
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<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,315 ⟶ 1,368:
<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>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,326 ⟶ 1,379:
 
=={{header|PILOT}}==
<langsyntaxhighlight lang="pilot">C :max=200
:n=1
*num
Line 1,354 ⟶ 1,407:
:a=b
J (a>0):*revloop
E :</langsyntaxhighlight>
{{out}}
<pre style='height:50ex;'>1
Line 1,431 ⟶ 1,484:
 
=={{header|PL/I}}==
<langsyntaxhighlight lang="pli">specialDivisors: procedure options(main);
%replace MAX by 200;
 
Line 1,462 ⟶ 1,515:
end;
end;
end specialDivisors;</langsyntaxhighlight>
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 11
Line 1,472 ⟶ 1,525:
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)
<lang plm>100H: /* FIND NUMBERS WHOSE REVERSED DIVISORS DIVIDE THE REVERSED NUMBER */
<syntaxhighlight lang="pli">100H: /* FIND NUMBERS WHOSE REVERSED DIVISORS DIVIDE THE REVERSED NUMBER */
 
DECLARE TRUE LITERALLY '0FFH';
Line 1,543 ⟶ 1,599:
CALL PRINT$NUMBER( MAX$SD + 1 );
CALL PRINT$NL;
EOF</langsyntaxhighlight>
{{out}}
<pre>
Line 1,556 ⟶ 1,612:
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" perl6line>use Prime::Factor:ver<0.3.0+>;
 
say "{+$_} matching numbers:\n{.batch(10)».fmt('%3d').join: "\n"}"
given (1..^200).grep: { all .flip «%%« .&divisors».flip };</langsyntaxhighlight>
{{out}}
<pre>72 matching numbers:
Line 1,574 ⟶ 1,842:
 
=={{header|REXX}}==
<langsyntaxhighlight lang="rexx">/*REXX program finds special divisors: numbers N such that reverse(D) divides ··· */
/*────────────────────────── reverse(N) for all divisors D of N, where N < 200. */
parse arg hi cols . /*obtain optional argument from the CL.*/
Line 1,601 ⟶ 1,869:
if cols>0 then say '───────┴'center("" , 1 + cols*(w+1), '─')
say
say 'Found ' found title</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
Line 1,620 ⟶ 1,888:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
load "stdlib.ring"
 
Line 1,664 ⟶ 1,932:
next
return rev
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,679 ⟶ 1,947:
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}}==
<langsyntaxhighlight lang="ruby">1..200 -> grep {|n| n.divisors.all {|d| d.flip `divides` n.flip } }.say</langsyntaxhighlight>
{{out}}
<pre>
Line 1,688 ⟶ 2,041:
 
=={{header|Swift}}==
<langsyntaxhighlight lang="swift">import Foundation
 
func reverse(_ number: Int) -> Int {
Line 1,726 ⟶ 2,079:
}
}
print("\n\(count) numbers found.")</langsyntaxhighlight>
 
{{out}}
Line 1,743 ⟶ 2,096:
=={{header|Wren}}==
{{libheader|Wren-math}}
{{libheader|Wren-seq}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight ecmascriptlang="wren">import "./math" for Int
import "./seqfmt" for LstFmt
import "/fmt" for Fmt
 
var reversed = Fn.new { |n|
Line 1,765 ⟶ 2,116:
}
System.print("Special divisors in the range 0..199:")
Fmt.tprint("$3d", special, 12)
for (chunk in Lst.chunks(special, 12)) Fmt.print("$3d", chunk)
System.print("\n%(special.count) special divisors found.")</langsyntaxhighlight>
 
{{out}}
Line 1,782 ⟶ 2,133:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">func Reverse(N); \Reverse the order of the digits
int N, M;
[M:= 0;
Line 1,815 ⟶ 2,166:
IntOut(0, Count);
Text(0, " such numbers found.");
]</langsyntaxhighlight>
 
{{out}}
Line 1,829 ⟶ 2,180:
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}}==
<langsyntaxhighlight lang="zig">const MAX = 200; // max number to check
const N = u16; // smallest integer type that fits
 
Line 1,863 ⟶ 2,233:
}
try stdout.print("\n", .{});
}</langsyntaxhighlight>
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 11
258

edits