Iccanobif primes: Difference between revisions

→‎J: fix wrong result
(Added Quackery.)
(→‎J: fix wrong result)
Line 537:
 
=={{header|J}}==
 
Implementation:
<syntaxhighlight lang=J"j"> (#~ 1 &p:]) |.&.|":"0 (, _2 +/@{. ])^:(70]) 1
 
2 3 5 31 43 773 7951 64901 52057 393121 56577108676171</syntaxhighlight>
<syntaxhighlight lang=J> (#~ 1 p:])|.&.|:"0 (, _2 +/@{. ])^:70]1
In other words,: 70 numbers from the fibonacciFibonacci sequence, reverse their digits, and keep those which are prime.
2 3 5 13 89 233 1597 28657 514229 433494437 2971215073
</syntaxhighlight>
 
In other words, 70 numbers from the fibonacci sequence, reverse their digits, and keep those which are prime.
 
Stretch:
<syntaxhighlight lang="Jj"> #@":@> 10}. (#~ 1&p:) |.&.(10&#.inv)"0 (, _2 +/@{. ])^:20000]1x
 
<syntaxhighlight lang="J"> #@":@> 10}. (#~ 1&p:)|.&.(10&#.inv)"0 (, _2 +/@{. ])^:20000]1x
14 21 37 40 80 104 137 330 406 409 503 888 1020 1122 1911 1947 2283 3727</syntaxhighlight>
 
For the stretch goal we use extended precision integers instead of the usual fixed width representation, and reverse the digits numerically rather than relying on the character representation of the numbers (though it's simplest to rely on the character representation for counting the digits of the resulting primes).
 
559

edits