First 9 prime Fibonacci number: Difference between revisions

Add Refal
(Add Refal)
(26 intermediate revisions by 17 users not shown)
Line 3:
;Task:
<br>Show on this page the first 9 prime Fibonacci numbers.
 
=={{header|11l}}==
{{trans|Python}}
 
<syntaxhighlight lang="11l">
F prime(x)
I x < 2
R 0B
I x == 2 | x == 3
R 1B
I x % 2 == 0
R 0B
L(i) (3 .. Int(sqrt(x))).step(2)
I x % i == 0
R 0B
R 1B
 
V n = 11
V fibn = 3
V (a, b) = (Int64(1), Int64(1))
L n > 0
(a, b) = (b, a + b)
I prime(b)
print(‘fib(#.): #.’.format(fibn, b))
n--
fibn++
</syntaxhighlight>
 
{{out}}
<pre>
fib(3): 2
fib(4): 3
fib(5): 5
fib(7): 13
fib(11): 89
fib(13): 233
fib(17): 1597
fib(23): 28657
fib(29): 514229
fib(43): 433494437
fib(47): 2971215073
</pre>
 
=={{header|ABC}}==
<syntaxhighlight lang="abc">HOW TO REPORT prime n:
REPORT n>=2 AND NO d IN {2..floor (root n)} HAS n mod d = 0
 
PUT 1, 1 IN a, b
PUT 0 IN n
WHILE n<9:
IF prime a:
WRITE a/
PUT n+1 IN n
PUT b, a+b IN a, b</syntaxhighlight>
{{out}}
<pre>2
3
5
13
89
233
1597
28657
514229</pre>
 
=={{header|Ada}}==
<syntaxhighlight lang="ada">with Ada.Text_IO;
 
procedure Prime_Fibonacci is
 
function Is_Prime (A : Natural) return Boolean is
D : Natural;
begin
if A < 2 then return False; end if;
if A in 2 .. 3 then return True; end if;
if A mod 2 = 0 then return False; end if;
if A mod 3 = 0 then return False; end if;
D := 5;
while D * D <= A loop
if A mod D = 0 then
return False;
end if;
D := D + 2;
if A mod D = 0 then
return False;
end if;
D := D + 4;
end loop;
return True;
end Is_Prime;
 
F_1 : Natural := 0;
F_2 : Natural := 1;
 
function Fibonacci return Natural is
R : Natural := F_1 + F_2;
begin
F_1 := F_2;
F_2 := R;
return R;
end Fibonacci;
 
Count : Natural := 0;
Fib : Natural;
begin
while Count < 9 loop
Fib := Fibonacci;
if Is_Prime (Fib) then
Count := Count + 1;
Ada.Text_IO.Put_Line (Fib'Image);
end if;
end loop;
end Prime_Fibonacci;</syntaxhighlight>
{{out}}
<pre>
2
3
5
13
89
233
1597
28657
514229
</pre>
 
=={{header|ALGOL 68}}==
{{libheader|ALGOL 68-primes}}
<langsyntaxhighlight lang="algol68">BEGIN # show the first 9 prime fibonacci numbers #
PR read "primes.incl.a68" PR # include prime utilities #
INT p count := 0;
Line 21 ⟶ 146:
FI
OD
END</langsyntaxhighlight>
{{out}}
<pre>
2 3 5 13 89 233 1597 28657 514229
</pre>
 
=={{header|ALGOL W}}==
<syntaxhighlight lang="ada">begin % -- show the first 9 prime fibonacci numbers %
 
% -- returns true if n is prime, false otherwise - uses trial division %
logical procedure isPrime ( integer value n ) ;
if n < 3 then n = 2
else if not odd( n ) then false
else begin
logical prime;
prime := true;
for i := 3 step 2 until entier( sqrt( n ) ) do begin
prime := n rem i not = 0;
if not prime then goto endTest;
end for_i;
endTest: prime
end isPrime ;
 
begin % -- task %
integer pCount, prev, curr, next;
pCount := 0;
prev := 0;
curr := 1;
while pCount < 9 do begin
next := prev + curr;
prev := curr;
curr := next;
if isPrime( curr ) then begin
pCount := pCount + 1;
writeon( i_w := 1, s_w := 0, " ", curr )
end if_isPrime__curr
end while_pCount_lt_9
end task
end.</syntaxhighlight>
{{out}}
<pre>
2 3 5 13 89 233 1597 28657 514229
</pre>
 
=={{header|Arturo}}==
 
<syntaxhighlight lang="arturo">fib: $[x][
if? x<2 [1]
else [(fib x-1) + (fib x-2)]
]
 
firstPrimeFibos: select.first:9 2..∞ 'n -> prime? fib n
 
loop firstPrimeFibos 'f ->
print ["F(" ++ (to :string f+1) ++ ") =" fib f]</syntaxhighlight>
 
{{out}}
 
<pre>F(3) = 2
F(4) = 3
F(5) = 5
F(7) = 13
F(11) = 89
F(13) = 233
F(17) = 1597
F(23) = 28657
F(29) = 514229</pre>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f FIRST_9_PRIME_FIBONACCI_NUMBER.AWK
BEGIN {
Line 58 ⟶ 246:
return(1)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 64 ⟶ 252:
2 3 5 13 89 233 1597 28657 514229
</pre>
 
 
=={{header|BASIC}}==
==={{header|BASIC256}}===
<langsyntaxhighlight BASIC256lang="basic256">function isPrime(v)
if v < 2 then return False
if v mod 2 = 0 then return v = 2
Line 100 ⟶ 287:
end if
end while
end</langsyntaxhighlight>
{{out}}
<pre>
Line 107 ⟶ 294:
 
==={{header|FreeBASIC}}===
<langsyntaxhighlight lang="freebasic">Function isPrime(Byval ValorEval As Integer) As Boolean
If ValorEval <= 1 Then Return False
For i As Integer = 2 To Int(Sqr(ValorEval))
Line 135 ⟶ 322:
End If
Loop
Sleep</langsyntaxhighlight>
{{out}}
<pre>The first 9 Prime Fibonacci numbers:
Line 141 ⟶ 328:
 
==={{header|PureBasic}}===
<langsyntaxhighlight PureBasiclang="purebasic">Procedure isPrime(v.i)
If v <= 1 : ProcedureReturn #False
ElseIf v < 4 : ProcedureReturn #True
Line 185 ⟶ 372:
PrintN(#CRLF$ + "--- terminado, pulsa RETURN---"): Input()
CloseConsole()
EndIf</langsyntaxhighlight>
{{out}}
<pre>
Line 192 ⟶ 379:
 
==={{header|Yabasic}}===
<langsyntaxhighlight lang="yabasic">sub isPrime(v)
if v < 2 then return False : fi
if mod(v, 2) = 0 then return v = 2 : fi
Line 224 ⟶ 411:
end if
loop
end</langsyntaxhighlight>
{{out}}
<pre>
Line 234 ⟶ 421:
{{trans|Wren}}
Requires C99 or later.
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
Line 267 ⟶ 454:
printf("\n");
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 278 ⟶ 465:
{{libheader|GMP}}
{{libheader|Primesieve}}
<langsyntaxhighlight lang="cpp">#include <chrono>
#include <iostream>
#include <sstream>
#include <utility>
#include <primesieve.hpp>
Line 332 ⟶ 518:
std::string to_string(const big_int& n) {
std::string str = n.get_str();
ifsize_t len = (str.size() > 40) {;
if (len > 40) {
std::ostringstream os;
os << str.substrreplace(020, 20)len <<- 40, "..." << str.substr(str.size() - 20) << " (";
<< str.size() <<+= " digits)(";
return os.str += std::to_string(len);
str += " digits)";
}
return str;
Line 351 ⟶ 538:
std::chrono::duration<double> ms(finish - start);
std::cout << "elapsed time: " << ms.count() << " seconds\n";
}</langsyntaxhighlight>
 
{{out}}
Line 385 ⟶ 572:
 
=={{header|CLU}}==
<langsyntaxhighlight lang="clu">fibonacci = iter () yields (int)
a: int := 1
b: int := 1
Line 418 ⟶ 605:
end
end
end start_up</langsyntaxhighlight>
{{out}}
<pre>2
Line 431 ⟶ 618:
 
=={{header|COBOL}}==
<langsyntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. PRIME-FIBONACCI.
Line 494 ⟶ 681:
IF FIB IS EQUAL TO 2 OR 3, MOVE 'X' TO PRIME-FLAG.
DONE.
EXIT.</langsyntaxhighlight>
{{out}}
<pre> 2
Line 507 ⟶ 694:
 
=={{header|Comal}}==
<langsyntaxhighlight lang="comal">0010 FUNC prime(n) CLOSED
0020 IF n<4 THEN RETURN n=2 OR n=3
0030 IF n MOD 2=0 OR n MOD 3=0 THEN RETURN FALSE
Line 529 ⟶ 716:
0210 c:=a+b;a:=b;b:=c
0220 ENDWHILE
0230 END</langsyntaxhighlight>
{{out}}
<pre>
Line 543 ⟶ 730:
 
=={{header|Cowgol}}==
<langsyntaxhighlight lang="cowgol">include "cowgol.coh";
 
sub prime(n: uint32): (p: uint8) is
Line 576 ⟶ 763:
a := b;
b := c;
end loop;</langsyntaxhighlight>
{{out}}
<pre>2
Line 587 ⟶ 774:
28657
514229</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
<syntaxhighlight lang="Delphi">
function IsPrime(N: integer): boolean;
{Fast, optimised prime test}
var I,Stop: integer;
begin
if (N = 2) or (N=3) then Result:=true
else if (n <= 1) or ((n mod 2) = 0) or ((n mod 3) = 0) then Result:= false
else
begin
I:=5;
Stop:=Trunc(sqrt(N));
Result:=False;
while I<=Stop do
begin
if ((N mod I) = 0) or ((N mod (I + 2)) = 0) then exit;
Inc(I,6);
end;
Result:=True;
end;
end;
 
 
procedure ShowFibonacciPrimes(Memo: TMemo);
{Find and display first nine Fibonacci primes}
var N1,N2,T,Cnt: integer;
begin
Cnt:=0;
N1:=0; N2:=1;
while true do
begin
{Calculate next Fib number}
T:=N1+N2;
N1:=N2; N2:=T;
{Test if it is prime}
if IsPrime(N2) then
begin
Inc(Cnt);
Memo.Lines.Add(IntToStr(N2));
if Cnt>=9 then break;
end;
end;
end;
</syntaxhighlight>
{{out}}
<pre>
2
3
5
13
89
233
1597
28657
514229
</pre>
 
=={{header|Draco}}==
<langsyntaxhighlight lang="draco">proc nonrec prime(ulong n) bool:
bool comp;
ulong d;
Line 623 ⟶ 870:
b := c
od
corp</langsyntaxhighlight>
{{out}}
<pre>2
Line 634 ⟶ 881:
28657
514229</pre>
 
=={{header|EasyLang}}==
<syntaxhighlight>
fastfunc isprim num .
i = 2
while i <= sqrt num
if num mod i = 0
return 0
.
i += 1
.
return 1
.
prev = 1
val = 1
while cnt < 9
h = prev + val
prev = val
val = h
if isprim val = 1
write val & " "
cnt += 1
.
.
</syntaxhighlight>
{{out}}
<pre>
2 3 5 13 89 233 1597 28657 514229
</pre>
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">
// Prime Fibonacci Numbers. Nigel Galloway: January 21st., 2022
seq{yield! [2I;3I]; yield! MathNet.Numerics.Generate.FibonacciSequence()|>Seq.skip 5|>Seq.filter(fun n->n%4I=1I && Open.Numeric.Primes.MillerRabin.IsProbablePrime &n)}|>Seq.take 23|>Seq.iteri(fun n g->printfn "%2d->%A" (n+1) g)
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 669 ⟶ 945:
=={{header|Factor}}==
{{works with|Factor|0.99 2021-06-02}}
<langsyntaxhighlight lang="factor">USING: kernel lists lists.lazy math.primes prettyprint sequences ;
 
: prime-fib ( -- list )
Line 675 ⟶ 951:
[ second ] lmap-lazy [ prime? ] lfilter ;
 
9 prime-fib ltake [ . ] leach</langsyntaxhighlight>
{{out}}
<pre>
Line 688 ⟶ 964:
514229
</pre>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
 
 
local fn IsPrime( n as UInt64 ) as BOOL
UInt64 i
BOOL result
if ( n < 2 ) then result = NO : exit fn
for i = 2 to n + 1
if ( i * i <= n ) and ( n mod i == 0 ) then result = NO : exit fn
next
result = YES
end fn = result
 
 
void local fn FindFibonacciPrimes( limit as long )
UInt64 f1 = 1, f2 = 1, f3
long count = 0
NSLog( @"The first %d prime Fibonacci numbers are:\n", limit )
while ( count < limit )
f3 = f1 + f2
if ( fn IsPrime( f3 ) )
NSLog( @"%ld ", f3 )
count++
end if
f1 = f2
f2 = f3
wend
NSLog( @"\n" )
end fn
 
fn FindFibonacciPrimes( 10 )
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
The first 10 prime Fibonacci numbers are:
 
2
3
5
13
89
233
1597
28657
514229
433494437
</pre>
 
 
=={{header|Go}}==
{{trans|C}}
<langsyntaxhighlight lang="go">package main
 
import "fmt"
Line 735 ⟶ 1,068:
}
fmt.Println()
}</langsyntaxhighlight>
 
{{out}}
Line 747 ⟶ 1,080:
Here, we pick a convenient expression and [https://code.jsoftware.com/wiki/Essays/Fibonacci_Sequence generate fibonacci numbers]
 
<langsyntaxhighlight Jlang="j">fib=: <. 0.5 + (%:5) %~ (2 %~ 1+%:5)^i.63</langsyntaxhighlight>
 
Then we select the first 9 which are prime:
 
<langsyntaxhighlight Jlang="j"> 9 {. (#~ 1&p:) fib
2 3 5 13 89 233 1597 28657 514229</langsyntaxhighlight>
 
=={{header|jq}}==
Line 763 ⟶ 1,096:
 
(*) For unlimited precision integer arithmetic, use gojq.
<langsyntaxhighlight lang="jq"># Emit an unbounded stream of Fibonacci numbers
def fibonaccis:
# input: [f(i-2), f(i-1)]
Line 773 ⟶ 1,106:
 
"The first 9 prime Fibonacci numbers are:",
limit(9; fibonaccis | select(is_prime))</langsyntaxhighlight>
{{out}}
<pre>
Line 790 ⟶ 1,123:
=={{header|Java}}==
Uses the PrimeGenerator class from [[Extensible prime generator#Java]].
<langsyntaxhighlight lang="java">import java.math.BigInteger;
 
public class PrimeFibonacciGenerator {
Line 849 ⟶ 1,182:
return str;
}
}</langsyntaxhighlight>
 
{{out}}
Line 883 ⟶ 1,216:
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">using Lazy
using Primes
 
Line 891 ⟶ 1,224:
 
println(take(9, primefibs)) # List: (2 3 5 13 89 233 1597 28657 514229)
</syntaxhighlight>
</lang>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
First solution by guessing some upper bound:
<langsyntaxhighlight Mathematicalang="mathematica">Select[Fibonacci /@ Range[100], PrimeQ, 9]</langsyntaxhighlight>
{{out}}
<pre>{2, 3, 5, 13, 89, 233, 1597, 28657, 514229}</pre>
 
Second solution without guessing some upper bound:
<langsyntaxhighlight Mathematicalang="mathematica">list = {};
Do[
f = Fibonacci[i];
Line 911 ⟶ 1,244:
];
out=Row[{"F(",#1,") = ",If[IntegerLength[#2]<=10,#2,Row@Catenate[{Take[IntegerDigits[#2],5],{" \[Ellipsis] "},Take[IntegerDigits[#2],-5],{" (",IntegerLength[#2]," digits)"}}]]}]&@@@list;
TableForm[out,TableHeadings->{Automatic,None}]</langsyntaxhighlight>
{{out}}
<pre>1 F(3) = 2
Line 939 ⟶ 1,272:
25 F(9311) = 34232 … 76289 (1946 digits)
26 F(9677) = 10565 … 70357 (2023 digits)</pre>
 
=={{header|Miranda}}==
<syntaxhighlight lang="miranda">main :: [sys_message]
main = [(Stdout . lay . map show . take 9 . filter prime) fibo]
 
fibo :: [num]
fibo = 1 : 1 : [a + b | (a,b) <- zip2 fibo (tl fibo)]
 
prime :: num->bool
prime n = n=2 \/ n=3, if n<=4
prime n = False, if or [n mod 2=0, n mod 3=0]
prime n = and [n mod d ~= 0 | d <- [3, 5..entier (sqrt n)]]</syntaxhighlight>
{{out}}
<pre>2
3
5
13
89
233
1597
28657
514229</pre>
 
=={{header|Nim}}==
<syntaxhighlight lang="Nim">func isPrime(n: Natural): bool =
## Return "true" is "n" is prime.
if n < 2: return false
if (n and 1) == 0: return n == 2
if n mod 3 == 0: return n == 3
var d = 5
var step = 2
while d * d <= n:
if n mod d == 0:
return false
inc d, step
step = 6 - step
return true
 
iterator fib(): int =
var prev = 0
var curr = 1
while true:
yield curr
swap prev, curr
inc curr, prev
 
echo "The first 9 prime Fibonacci numbers are:"
var count = 0
for n in fib():
if n.isPrime:
stdout.write n, ' '
inc count
if count == 9:
echo()
break
</syntaxhighlight>
 
{{out}}
<pre>The first 9 prime Fibonacci numbers are:
2 3 5 13 89 233 1597 28657 514229
</pre>
 
=={{header|OCaml}}==
<syntaxhighlight lang="ocaml">let is_prime n =
let rec test x =
x * x > n || n mod x <> 0 && n mod (x + 2) <> 0 && test (x + 6)
in
if n < 5
then n land 2 <> 0
else n land 1 <> 0 && n mod 3 <> 0 && test 5
 
let seq_fibonacci =
let rec next b a () = Seq.Cons (a, next (b + a) b) in
next 1 0
 
let () =
seq_fibonacci |> Seq.filter is_prime |> Seq.take 9
|> Seq.iter (Printf.printf " %u") |> print_newline</syntaxhighlight>
{{out}}
<pre> 2 3 5 13 89 233 1597 28657 514229</pre>
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">#!/usr/bin/perl
 
use strict; # https://rosettacode.org/wiki/First_9_Prime_Fibonacci_Number
Line 954 ⟶ 1,367:
is_prime( $x ) and push @first, $x;
}
print "@first\n";</langsyntaxhighlight>
{{out}}
<pre>
Line 963 ⟶ 1,376:
{{libheader|Phix/online}}
You can run this online [http://phix.x10.mx/p2js/primefib.htm here].
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">include</span> <span style="color: #004080;">mpfr</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
Line 982 ⟶ 1,395:
<span style="color: #000000;">n</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,015 ⟶ 1,428:
=={{header|Pike}}==
{{trans|C}}
<langsyntaxhighlight Pikelang="pike">bool isPrime(int n) {
if (n < 2) {
return false;
Line 1,061 ⟶ 1,474:
write("\n");
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>The first 12 prime Fibonacci numbers are:
Line 1,067 ⟶ 1,480:
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">
2 things:
print("working...")
"""for the Fibonacci sequence: an even number is following after 2 odd numbers. Eliminate time to check whether it is prime or not because even numbers are not primes.
print("The firsr 9 Prime Fibonacci numbers:")
for prime numbers: it becomes bigger and bigger. The original algorithm will be slow for super big number. In this case, I use Miller Rabin primality test.
 
P/S: I am not surprised. It is fast but still cannot compare to other languages such as C++ or Rust or .... After all, Python is still slow :P"""
num = 0
 
def isprimemiller_rabin(mn, k=5):
forif in in< range(2,int(m**0.5)+1):
ifreturn m%i==0:False
for p in [2, 3, 5, 7, 11]:
if n < p * p:
return True
if n % p == 0:
return False
r, s = 0, n - 1
while s % 2 == 0:
r += 1
s //= 2
for _ in range(k):
a = random.randint(2, n - 1)
x = pow(a, s, n)
if x == 1 or x == n - 1:
continue
for _ in range(r - 1):
x = pow(x, 2, n)
if x == n - 1:
break
else:
return False
return True
 
def fib(nr):
if (nr == 0):
return 0
if (nr == 1):
return 1
if (nr > 1):
return fib(nr-1) + fib(nr-2)
 
def format_large_number(n):
for n in range(2,520000):
x s = fibstr(n)
if isprimelen(xs) > 50:
return "%s...%s (Total %d digits)" % (s[:10], s[-10:], len(s))
num = num + 1
return s
if (x > 1):
if (num < 11):
print(str(x),end=" ")
else:
break
 
 
print()
def prime_fibonacci(n):
print("done...")
a, b = 1, 1
</lang>
fibn = 2
odd_count = 0
start = time()
 
while n > 0:
if a == 2 or (a % 2 != 0 and miller_rabin(a)):
print("fib(%d): %s (%s s)" % (fibn - 1, format_large_number(a), time() - start))
n -= 1
if a % 2 != 0:
odd_count += 1
else:
odd_count = 0
else:
odd_count = 0
 
if odd_count == 2:
a, b = b, a + b
fibn += 1
odd_count = 1
continue
 
a, b = b, a + b
fibn += 1
 
 
prime_fibonacci(26)
 
</syntaxhighlight>
{{out}}
<pre>
 
working...
fib(3): 2 (0.0 s)
The firsr 9 Prime Fibonacci numbers:
fib(4): 3 (0.0 s)
2 3 5 13 89 233 1597 28657 514229
fib(5): 5 (0.0 s)
done...
fib(7): 13 (0.0 s)
fib(11): 89 (0.0 s)
fib(13): 233 (0.0 s)
fib(17): 1597 (0.0 s)
fib(23): 28657 (0.0 s)
fib(29): 514229 (0.0 s)
fib(43): 433494437 (0.0 s)
fib(47): 2971215073 (0.0 s)
fib(83): 99194853094755497 (0.0009968280792236328 s)
fib(131): 1066340417491710595814572169 (0.0009968280792236328 s)
fib(137): 19134702400093278081449423917 (0.0009968280792236328 s)
fib(359): 4754204377...6935476241 (Total 75 digits) (0.009973287582397461 s)
fib(431): 5298927110...9676262369 (Total 90 digits) (0.017951488494873047 s)
fib(433): 1387277127...3712568353 (Total 91 digits) (0.018948078155517578 s)
fib(449): 3061719992...2805665949 (Total 94 digits) (0.021939992904663086 s)
fib(509): 1059799926...9876129909 (Total 107 digits) (0.034908294677734375 s)
fib(569): 3668447431...7781065869 (Total 119 digits) (0.0468745231628418 s)
fib(571): 9604120061...3008074629 (Total 119 digits) (0.050863027572631836 s)
fib(2971): 3571035606...8470316229 (Total 621 digits) (9.068741798400879 s)
fib(4723): 5001956361...0053591957 (Total 987 digits) (52.320056200027466 s)
fib(5387): 2930441286...4725855833 (Total 1126 digits) (86.49367618560791 s)
fib(9311): 3423208606...4669476289 (Total 1946 digits) (686.371306180954 s)
fib(9677): 1056597787...4550670357 (Total 2023 digits) (795.5426495075226 s)
 
 
</pre>
 
=={{header|Quackery}}==
 
<code>isprime</code> is defined at [[Primality by trial division#Quackery]].
 
<syntaxhighlight lang="Quackery"> 1 1 []
[ dip [ tuck + ]
over isprime iff
[ over join
dup size 9 = ]
else false
until ]
echo 2drop</syntaxhighlight>
 
{{out}}
 
<pre>[ 2 3 5 13 89 233 1597 28657 514229 ]</pre>
 
=={{header|Raku}}==
 
<syntaxhighlight lang="raku" perl6line>put ++$ .fmt("%2d: ") ~ $_ for (0, 1, * + * … *).grep( &is-prime )[^20];</langsyntaxhighlight>
{{out}}
<pre> 1: 2
Line 1,133 ⟶ 1,625:
20: 36684474316080978061473613646275630451100586901195229815270242868417768061193560857904335017879540515228143777781065869</pre>
 
=={{header|Refal}}==
<syntaxhighlight lang="refal">$ENTRY Go {
= <Prout <Gen 9 Prime Fibo (1 1)>>;
}
 
Gen {
0 s.Filter s.Gen (e.State) = ;
s.N s.Filter s.Gen (e.State),
<Mu s.Gen (e.State)>: (e.Next) e.Val,
<Mu s.Filter e.Val>: {
True = e.Val <Gen <- s.N 1> s.Filter s.Gen (e.Next)>;
False = <Gen s.N s.Filter s.Gen (e.Next)>;
};
};
 
Fibo {
(s.A s.B) = (s.B <+ s.A s.B>) s.A;
};
 
Prime {
0 = False; 1 = False;
2 = True; 3 = True;
s.N, <Mod s.N 2>: 0 = False;
s.N, <Mod s.N 3>: 0 = False;
s.N = <Prime1 s.N 5>;
};
 
Prime1 {
s.N s.D, <Compare s.N <* s.D s.D>>: '-' = True;
s.N s.D, <Mod s.N s.D>: 0 = False;
s.N s.D = <Prime1 s.N <+ 2 s.D>>;
};</syntaxhighlight>
{{out}}
<pre>2 3 5 13 89 233 1597 28657 514229</pre>
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
load "stdlibcore.ring"
see "working..." + nl
Line 1,158 ⟶ 1,684:
if nr = 1 return 1 ok
if nr > 1 return fib(nr-1) + fib(nr-2) ok
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,168 ⟶ 1,694:
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">// [dependencies]
// rug = "1.15.0"
// primal = "0.3"
Line 1,231 ⟶ 1,757:
let time = now.elapsed();
println!("elapsed time: {} milliseconds", time.as_millis());
}</langsyntaxhighlight>
 
{{out}}
Line 1,263 ⟶ 1,789:
elapsed time: 22642 milliseconds
</pre>
 
=={{header|RPL}}==
≪ { } 0 1
'''WHILE''' 3 PICK SIZE 9 < '''REPEAT'''
SWAP OVER +
'''IF''' DUP ISPRIME? '''THEN''' ROT OVER + UNROT '''END'''
'''END''' DROP2
≫ '<span style="color:blue">TASK</span>' STO
{{out}}
<pre>
1: { 2 3 5 13 89 233 1597 28657 514229 }
</pre>
 
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">require 'prime'
 
prime_fibs = Enumerator.new do |y|
a, b = 1, 1
loop do
y << a if a.prime?
a, b = b, a + b
end
end
puts prime_fibs.take(9)</syntaxhighlight>
{{out}}
<pre>
[2, 3, 5, 13, 89, 233, 1597, 28657, 514229]
</pre>
 
=={{header|SETL}}==
<syntaxhighlight lang="setl">program prime_fibonacci;
[a, b] := [1, 1];
loop until seen = 9 do
if prime a then
print(a);
seen +:= 1;
end if;
[a, b] := [b, a+b];
end loop;
 
op prime(n);
if n<=4 then
return n in {2, 3};
end if;
if n mod 2 = 0 or n mod 3 = 0 then
return false;
end if;
d := 5;
loop while d*d <= n do
if n mod d = 0 then return false; end if;
d +:= 2;
if n mod d = 0 then return false; end if;
d +:= 4;
end loop;
return true;
end op;
end program;</syntaxhighlight>
{{out}}
<pre>2
3
5
13
89
233
1597
28657
514229</pre>
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">say 12.by { .fib.is_prime }.map { .fib }</langsyntaxhighlight>
{{out}}
<pre>
Line 1,273 ⟶ 1,866:
=={{header|Wren}}==
{{libheader|Wren-math}}
<langsyntaxhighlight ecmascriptlang="wren">import "./math" for Int
 
var limit = 11 // as far as we can go without using BigInt
Line 1,289 ⟶ 1,882:
f2 = f3
}
System.print()</langsyntaxhighlight>
 
{{out}}
Line 1,298 ⟶ 1,891:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">func IsPrime(N); \Return 'true' if N is prime
int N, I;
[if N <= 2 then return N = 2;
Line 1,320 ⟶ 1,913:
N:= F;
];
]</langsyntaxhighlight>
 
{{out}}
2,093

edits