Deceptive numbers: Difference between revisions

→‎{{header|Wren}}: Added a version which doesn't use big integers.
(→‎Python: add an optimized variant, ~35% faster)
(→‎{{header|Wren}}: Added a version which doesn't use big integers.)
Line 1,271:
[91, 259, 451, 481, 703, 1729, 2821, 2981, 3367, 4141, 4187, 5461, 6533, 6541, 6601, 7471, 7777, 8149, 8401, 8911, 10001, 11111, 12403, 13981, 14701]
</pre>
 
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="ecmascript">import "./math" for Int
 
var count = 0
var limit = 25 // or 62
var n = 49
var deceptive = []
while (count < limit) {
if (!Int.isPrime(n) && n % 3 != 0 && n % 5 != 0 && Int.modPow(10, n-1, n) == 1) {
deceptive.add(n)
count = count + 1
}
n = n + 2
}
System.print("The first %(limit) deceptive numbers are:")
System.print(deceptive)</syntaxhighlight>
 
=={{header|XPL0}}==
9,477

edits