Special divisors: Difference between revisions

no edit summary
No edit summary
 
(5 intermediate revisions by 3 users not shown)
Line 1,343:
157 163 167 169 173 179 181 187 191 193
197 199</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|Phix}}==
Line 1,789 ⟶ 1,717:
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}}==
Line 1,912 ⟶ 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}}==
Line 1,937 ⟶ 1,998:
[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}}==
Line 2,001 ⟶ 2,096:
=={{header|Wren}}==
{{libheader|Wren-math}}
{{libheader|Wren-seq}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./math" for Int
import "./seqfmt" for LstFmt
import "/fmt" for Fmt
 
var reversed = Fn.new { |n|
Line 2,023 ⟶ 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.")</syntaxhighlight>
 
258

edits