Iccanobif primes: Difference between revisions

m
→‎{{header|J}}: discard f3 as unnecessary, and include some comments
m (→‎{{header|J}}: stretch)
m (→‎{{header|J}}: discard f3 as unnecessary, and include some comments)
Line 414:
=={{header|J}}==
 
Implementation:
Borrowing <code>f3</code> from [[j:Essays/Fibonacci_Sequence#Power_of_phi|an essay on finding fibonacci numbers]]
 
<syntaxhighlight lang=J> f3=:(#~ {{1 <p:])|.0&.5 + (%|:5) %~"0 (2, %~_2 1+%:5/@{. ])^y }}:70]1
2 3 5 13 89 233 1597 28657 514229 433494437 2971215073
(#~ 1 p:])|.&.|:"0 f3 2+i.69
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:
Line 424 ⟶ 426:
<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, 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).
 
=={{header|jq}}==
6,962

edits