First 9 prime Fibonacci number: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) (→{{header|Raku}}: Add a Raku example) |
Thundergnat (talk | contribs) m (→{{header|Raku}}: slightly nicer layout) |
||
Line 6: | Line 6: | ||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
<lang perl6>put ++$ |
<lang perl6>put ++$ .fmt("%2d: ") ~ $_ for (0, 1, * + * … *).grep( &is-prime )[^20];</lang> |
||
{{out}} |
{{out}} |
||
<pre>1: 2 |
<pre> 1: 2 |
||
2: 3 |
2: 3 |
||
3: 5 |
3: 5 |
||
4: 13 |
4: 13 |
||
5: 89 |
5: 89 |
||
6: 233 |
6: 233 |
||
7: 1597 |
7: 1597 |
||
8: 28657 |
8: 28657 |
||
9: 514229 |
9: 514229 |
||
10: 433494437 |
10: 433494437 |
||
11: 2971215073 |
11: 2971215073 |
Revision as of 01:28, 20 January 2022
First 9 prime Fibonacci number is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
- Task
Show on this page the first 9 Fibonacci number.
Raku
<lang perl6>put ++$ .fmt("%2d: ") ~ $_ for (0, 1, * + * … *).grep( &is-prime )[^20];</lang>
- Output:
1: 2 2: 3 3: 5 4: 13 5: 89 6: 233 7: 1597 8: 28657 9: 514229 10: 433494437 11: 2971215073 12: 99194853094755497 13: 1066340417491710595814572169 14: 19134702400093278081449423917 15: 475420437734698220747368027166749382927701417016557193662268716376935476241 16: 529892711006095621792039556787784670197112759029534506620905162834769955134424689676262369 17: 1387277127804783827114186103186246392258450358171783690079918032136025225954602593712568353 18: 3061719992484545030554313848083717208111285432353738497131674799321571238149015933442805665949 19: 10597999265301490732599643671505003412515860435409421932560009680142974347195483140293254396195769876129909 20: 36684474316080978061473613646275630451100586901195229815270242868417768061193560857904335017879540515228143777781065869
Ring
<lang ring> load "stdlib.ring" see "working..." + nl num = 0
see "The firts 9 Prime Fibonacci numbers: " + nl for n = 1 to 1000000
x = fib(n) if isprime(x) num++ if num< 10 see "" + x + " " else exit ok ok
next
see "done..." + nl
func fib nr
if nr = 0 return 0 ok if nr = 1 return 1 ok if nr > 1 return fib(nr-1) + fib(nr-2) ok
</lang>
- Output:
working... Prime Fibonacci numbers: 2 3 5 13 89 233 1597 28657 514229 done...