lambdaway
::
deceptive
5
|
list
|
login
|
load
|
|
_h1 deceptive number '{/ 111111 7} = {/ 111111 7} _p Following [[rosettacode|https://rosettacode.org/wiki/Deceptive_numbers#Python]] {prewrap def is_deceptive(n): if n & 1 and n % 3 and n % 5: x = 7 while x * x <= n: if not (n % x and n % (x + 4)): return pow(10, n - 1, n * 9) == 1 x += 6 return False i, l = 49, [] while len(l) < 100: if is_deceptive(i): l.append(i) i += 1 print(*l) Output: 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 14911 15211 15841 19201 21931 22321 24013 24661 27613 29341 34133 34441 35113 38503 41041 45527 46657 48433 50851 50881 52633 54913 57181 63139 63973 65311 66991 67861 68101 75361 79003 82513 83119 94139 95161 97273 97681 100001 101101 101491 102173 108691 113201 115627 115921 118301 118957 122221 126217 128713 130351 131821 134821 134863 137137 137149 138481 139231 145181 147001 148417 152551 158497 162401 164761 166499 170017 172081 179881 188191 188269 188461 188501 196651 201917 '{def isdeceptive {def isdeceptive.loop {lambda {:n :x} {if {> {BN.* :x :x} :n} then {if {not {and {= {BN.% :n :x} 0} {= {BN.% :n {BN.+ :x 4}} 0}}} then {= 1 {mod-exp 10 {BN.- :n 1} {BN.* :n 9} 1}} else false} else {isdeceptive.loop :n {BN.+ :x 6}} }}} {lambda {:n} {if {not {and {= {BN.% :n 2} 1} {= {BN.% :n 3} 0} {= {BN.% :n 5} 0}}} then {isdeceptive.loop :n 7} else false }}} -> {def isdeceptive {def isdeceptive.loop {lambda {:n :x} {if {> {* :x :x} :n} then {if {not {and {= {% :n :x} 0} {= {% :n {+ :x 4}} 0}}} then {= 1 {mod-exp 10 {- :n 1} {* :n 9} 1}} else false} else {isdeceptive.loop :n {+ :x 6}} }}} {lambda {:n} {if {and {= {% :n 2} 1} {= {% :n 3} 0} {= {% :n 5} 0}} then false else {isdeceptive.loop :n 7} }}} '{S.replace \s by space in {S.map {lambda {:i} {if {isdeceptive :i} then :i else}} {S.serie 1 200}} } } _h2 mod-exp {prewrap {require lib_BN} {def BN.= {lambda {:a :b} {= {BN.compare :a :b} 0}}} -> BN.= {def BN.even? {lambda {:n} {= {BN.compare {BN.% :n 2} 0} 0}}} -> BN.even? {def BN.square {lambda {:n} {BN.* :n :n}}} -> BN.square {def mod-exp {lambda {:a :n :mod} {if {BN.= :n 0} then 1 else {if {BN.even? :n} then {BN.% {BN.square {mod-exp :a {BN./ :n 2} :mod}} :mod} else {BN.% {BN.* :a {mod-exp :a {BN.- :n 1} :mod}} :mod}}}}} -> mod-exp '{mod-exp 2988348162058574136915891421498819466320163312926952423791023078876139 2351399303373464486466122544523690094744975233415544072992656881240319 {BN.pow 10 40}} -> 1527229998585248450016808958343740453059 // 1700ms {def isprime {def isprime.loop {lambda {:n :m :i} {if {> :i :m} then true else {if {= {% :n :i} 0} then false else {isprime.loop :n :m {+ :i 2}} }}}} {lambda {:n} {if {= :n 1} then false else {if {or {= :n 2} {= :n 3} {= :n 5} {= :n 7}} then true else {if {or {< : n 2} {= {% :n 2} 0}} then false else {isprime.loop :n {sqrt :n} 3} }}}}} {isprime 1231} {S.replace \s by space in {S.map {lambda {:i} {if {jsdeceptive :i} then :i else •}} {S.serie 1 200}}} } _h2 xxx {pre def is_deceptive(n): if n & 1 and n % 3 and n % 5: x = 7 while x * x <= n: if not (n % x and n % (x + 4)): return pow(10, n - 1, n * 9) == 1 x += 6 return False i, l = 49, [] while len(l) < 100: if is_deceptive(i): l.append(i) i += 1 print(*l) } {script function power(x, y, p) { var res = 1; while (y > 0) { if (y%2 === 1) // y is odd res = res*x; y = y/2; // y must be even now x = x*x; } return res % p ; } var js_deceptive = function(n) { if ((n%2 !== 1) && (n%3 !== 1) && (n%5 !== 0)) { var x = 7; while (x*x <= n) { if (!(n%x !== 0 && n%(x+4) !== 0)) return (power(10,n-1,n*9) !== 1) x += 6; } } return false }; LAMBDATALK.DICT['jsdeceptive'] = function() { return js_deceptive( Number(arguments[0].trim() )) }; }
lambdaway v.20211111