Deceptive numbers: Difference between revisions

m
(added RPL)
(7 intermediate revisions by 5 users not shown)
Line 439:
137149 138481 139231 145181 147001 148417 152551 158497 162401 164761
166499 170017 172081 179881 188191 188269 188461 188501 196651 201917
</pre>
 
=={{header|EasyLang}}==
{{trans|C}}
<syntaxhighlight>
func modpow b e m .
r = 1
while e > 0
if e mod 2 = 1
r = r * b mod m
.
b = b * b mod m
e = e div 2
.
return r
.
func is_deceptive n .
if n mod 2 = 1 and n mod 3 <> 0 and n mod 5 <> 0
if modpow 10 (n - 1) n = 1
x = 7
while x * x <= n
if n mod x = 0 or n mod (x + 4) = 0
return 1
.
x += 6
.
.
.
.
while cnt < 10
n += 1
if is_deceptive n = 1
write n & " "
cnt += 1
.
.
</syntaxhighlight>
{{out}}
<pre>
91 259 451 481 703 1729 2821 2981 3367 4141
</pre>
 
Line 485 ⟶ 525:
if Isprime(n)>1 and Divides(n,Rep(n-1)) then !!n; c:+; fi
od;</syntaxhighlight>
 
=={{header|FreeBASIC}}==
{{trans|XPLo}}
<syntaxhighlight lang="vbnet">Function ModPow(b As Uinteger, e As Uinteger, m As Uinteger) As Uinteger
Dim As Uinteger p = 1
While e <> 0
If (e And 1) Then p = (p*b) Mod m
b = (b*b) Mod m
e Shr= 1
Wend
Return p
End Function
 
Function isDeceptive(n As Uinteger) As Uinteger
Dim As Uinteger x
If (n And 1) <> 0 Andalso (n Mod 3) <> 0 Andalso (n Mod 5) <> 0 Then
x = 7
While x*x <= n
If (n Mod x) = 0 Orelse (n Mod (x+4)) = 0 Then Return (ModPow(10, n-1, n) = 1)
x += 6
Wend
End If
Return 0
End Function
 
Dim As Uinteger c = 0, i = 49
While c <> 41 ' limit for signed 32-bit integers
If isDeceptive(i) Then
Print Using "#######"; Csng(i);
c += 1
If (c Mod 10) = 0 Then Print
End If
i += 1
Wend
 
Sleep</syntaxhighlight>
{{out}}
<pre>Same as XPLo entry.</pre>
 
=={{header|Go}}==
Line 683 ⟶ 761:
=={{header|langur}}==
{{trans|ALGOL 68}}
<syntaxhighlight lang="langur">val .isPrime = fn(.i) {
{{works with|langur|0.8.1}}
.i == 2 or .i > 2 and
<syntaxhighlight lang="langur">val .isPrime = f .i == 2 or .i > 2 and not any f(.x) .i div .x, pseries 2 .. .i ^/ 2
not any fn(.x) { .i div .x }, pseries 2 .. .i ^/ 2
}
 
var .nums = []
Line 690 ⟶ 770:
 
for .n = 9; len(.nums) < 10; .n += 2 {
.repunit = .repunit x* 100 + 11
if not .isPrime(.n) and .repunit div .n {
.nums = more .nums, .n
Line 1,270 ⟶ 1,350:
2 +
'''END''' DROP
» » '<span style="color:blue">TASK</span>' STO
Runs in 4 minutes on a HP-50g.
 
'''With a wheel:'''
« { 4 6 2 6 4 2 4 2 } DUP SIZE → wheel wsize
« { } 49
'''WHILE''' OVER SIZE 10 < '''REPEAT'''
1 wsize '''FOR''' j
'''IF''' DUP ISPRIME? NOT '''THEN'''
DUP MODSTO 10 OVER 1 - POWMOD
'''IF''' 1 == '''THEN''' SWAP OVER + SWAP '''END'''
'''END'''
wheel j GET +
'''NEXT'''
'''END''' DROP
» » '<span style="color:blue">TASK</span>' STO
Runs in 1:26 minutes on a HP-50g.
{{out}}
<pre>
1: { 91 259 451 481 703 1729 2821 2981 3367 4141 }
</pre>
Runs in 4 minutes on a HP-50g.
 
=={{header|Ruby}}==
Line 1,490 ⟶ 1,585:
 
The first 62 deceptive numbers (up to 97681 though not shown in full) are found in 0.179 seconds.
<syntaxhighlight lang="ecmascriptwren">/* deceptive_numbersDeceptive_numbers.wren */
 
import "./gmp" for Mpz
Line 1,520 ⟶ 1,615:
 
As discussed in the talk page, it is also possible to do this task without using big integers and the following version runs under Wren-cli albeit somewhat slower at 0.103 seconds for the first 25 deceptive numbers and 0.978 seconds for the first 62. The output is the same as the GMP version.
<syntaxhighlight lang="ecmascriptwren">import "./math" for Int
 
var count = 0
990

edits