Deceptive numbers: Difference between revisions

→‎J: simplify, much faster
(→‎J: simplify, much faster)
Line 530:
 
=={{header|J}}==
<syntaxhighlight lang="j">Rwheel=:. (10x4 #.6 2 6 4 2 4 #&1)"02
deceptivefermat=:. {{1&p: < 0 = ]10 (y&|@^) R@<: y}}"0
 
2+I.deceptive 2+i.10000
91 259 451 481 703 1729 2821 2981 3367 4141 4187 5461 6533 6541 6601 7471 7777 8149 8401 8911 10001</syntaxhighlight>
 
For improved performance:
 
<syntaxhighlight lang="j">deceptives=: {{
r=.$k=.10x #.}.1#~j=.9
while. y>#r do.
if. 0<2|j do.
if. 0<5|j do.
if. 0=1 p:j do.
if. 0=0]j|k do.
r=. r, j
end.
end.
end.
end.
k=. 1 10x p.k
j=. j+1
end.
r
}}</syntaxhighlight>
 
_10 ]\ (#~ fermat) (#~ 0&p:) +/\ 49 , 15e4 $ wheel</syntaxhighlight>
{{out}}
<pre>
<syntaxhighlight lang="j"> deceptives 21
91 259 451 481 703 1729 2821 2981703 3367 4141 41871729 5461 6533 65412821 6601 7471 77772981 8149 8401 89113367 10001</syntaxhighlight> 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
216001 216931 225589 226273 229633 231337 234421 237169 237817 245491
247753 248677 250717 251251 252601 253099 269011 269569 274231 281821
286903 287749 287809 294409 298033 301081 302177 304057 314821 334153
340561 341503 346801 351809 357641 364277 366337 372731 385003 390313
391141 399001 401401 410041 413339 420343 437251 451091 455971 458641
463241 463489 481601 488881 489997 491063 492101 497377 497503 497927
505363 507529 509971 511969 512461 520801 522349 530881 532171 552721
</pre>
 
=={{header|Java}}==
559

edits