First 9 prime Fibonacci number
Appearance
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 prime Fibonacci numbers.
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++
- Output:
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
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
- Output:
2 3 5 13 89 233 1597 28657 514229
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;
- Output:
2 3 5 13 89 233 1597 28657 514229
ALGOL 68
BEGIN # show the first 9 prime fibonacci numbers #
PR read "primes.incl.a68" PR # include prime utilities #
INT p count := 0;
INT prev := 0;
INT curr := 1;
WHILE p count < 9 DO
INT next = prev + curr;
prev := curr;
curr := next;
IF is probably prime( curr ) THEN
# have a prime fibonacci number #
p count +:= 1;
print( ( " ", whole( curr, 0 ) ) )
FI
OD
END
- Output:
2 3 5 13 89 233 1597 28657 514229
ALGOL W
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.
- Output:
2 3 5 13 89 233 1597 28657 514229
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]
- Output:
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
AWK
# syntax: GAWK -f FIRST_9_PRIME_FIBONACCI_NUMBER.AWK
BEGIN {
f1 = f2 = 1
stop = 9
printf("First %d Prime Fibonacci numbers:\n",stop)
while (count < stop) {
f3 = f1 + f2
if (is_prime(f3)) {
printf("%d ",f3)
count++
}
f1 = f2
f2 = f3
}
printf("\n")
exit(0)
}
function is_prime(n, d) {
d = 5
if (n < 2) { return(0) }
if (n % 2 == 0) { return(n == 2) }
if (n % 3 == 0) { return(n == 3) }
while (d*d <= n) {
if (n % d == 0) { return(0) }
d += 2
if (n % d == 0) { return(0) }
d += 4
}
return(1)
}
- Output:
First 9 Prime Fibonacci numbers: 2 3 5 13 89 233 1597 28657 514229
BASIC
BASIC256
include "isprime.kbs"
function fib(nr)
if nr = 0 then return 0
if nr = 1 then return 1
if nr > 1 then return fib(nr-1) + fib(nr-2)
end function
i = 0
cont = 0
print "The first 9 Prime Fibonacci numbers: "
do
i += 1
num = fib(i)
if isPrime(num) then
cont += 1
print num; " ";
end if
until cont >= 9
end
- Output:
Same as FreeBASIC entry.
FreeBASIC
#include "isprime.bas"
Function fib(nr As Integer) As Integer
If nr = 0 Then Return 0
If nr = 1 Then Return 1
If nr > 1 Then Return fib(nr-1) + fib(nr-2)
End Function
Dim As Integer i = 0, num, cont = 0
Print "The first 9 Prime Fibonacci numbers: "
Do
i += 1
num = fib(i)
If isprime(num) Then
cont += 1
If cont < 10 Then
Print num; " ";
Else
Exit Do
End If
End If
Loop
Sleep
- Output:
The first 9 Prime Fibonacci numbers: 2 3 5 13 89 233 1597 28657 514229
Gambas
Use "isprime.bas"
Public Sub Main()
Dim i As Integer = 0, num As Integer, cont As Integer = 0
Print "The first 9 Prime Fibonacci numbers: "
Do
i += 1
num = fib(i)
If isprime(num) Then
cont += 1
Print num; " ";
End If
Loop Until cont >= 9
End
Function fib(nr As Integer) As Integer
If nr = 0 Then Return 0
If nr = 1 Then Return 1
If nr > 1 Then Return fib(nr - 1) + fib(nr - 2)
End Function
- Output:
Same as FreeBASIC entry.
PureBasic
XIncludeFile "isprime.pb"
Procedure fib(nr.i)
If nr = 0 : ProcedureReturn 0
ElseIf nr = 1 : ProcedureReturn 1
ElseIf nr > 1 : ProcedureReturn fib(nr-1) + fib(nr-2)
EndIf
EndProcedure
If OpenConsole()
Define i.i = 0, cont.i = 0
PrintN("The first 9 Prime Fibonacci numbers: ")
Repeat
i + 1
num = fib(i)
If isprime(num)
cont + 1
If cont < 10
Print(Str(num) + " ")
Else
Break
EndIf
EndIf
ForEver
PrintN(#CRLF$ + "Press ENTER to exit"): Input()
CloseConsole()
EndIf
- Output:
Same as FreeBASIC entry.
Yabasic
import isprime
sub fib(nr)
if nr = 0 return 0
if nr = 1 return 1
if nr > 1 return fib(nr-1) + fib(nr-2)
end sub
i = 0
cont = 0
print "The first 9 Prime Fibonacci numbers: "
repeat
i = i + 1
num = fib(i)
if isPrime(num) then
cont = cont + 1
print num, " ";
fi
until cont >= 9
print
end
- Output:
Same as FreeBASIC entry.
C
Requires C99 or later.
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
bool isPrime(uint64_t n) {
if (n < 2) return false;
if (!(n%2)) return n == 2;
if (!(n%3)) return n == 3;
uint64_t d = 5;
while (d*d <= n) {
if (!(n%d)) return false;
d += 2;
if (!(n%d)) return false;
d += 4;
}
return true;
}
int main() {
uint64_t f1 = 1, f2 = 1, f3;
int count = 0, limit = 12; // as far as we can get without using GMP
printf("The first %d prime Fibonacci numbers are:\n", limit);
while (count < limit) {
f3 = f1 + f2;
if (isPrime(f3)) {
printf("%ld ", f3);
count++;
}
f1 = f2;
f2 = f3;
}
printf("\n");
return 0;
}
- Output:
The first 12 prime Fibonacci numbers are: 2 3 5 13 89 233 1597 28657 514229 433494437 2971215073 99194853094755497
C++
#include <chrono>
#include <iostream>
#include <utility>
#include <primesieve.hpp>
#include <gmpxx.h>
using big_int = mpz_class;
bool is_probably_prime(const big_int& n) {
return mpz_probab_prime_p(n.get_mpz_t(), 30) != 0;
}
class prime_fibonacci_generator {
public:
prime_fibonacci_generator();
std::pair<uint64_t, big_int> next();
private:
big_int next_fibonacci();
primesieve::iterator p_;
big_int f0_ = 0;
big_int f1_ = 1;
uint64_t n_ = 0;
};
prime_fibonacci_generator::prime_fibonacci_generator() {
for (int i = 0; i < 2; ++i)
p_.next_prime();
}
std::pair<uint64_t, big_int> prime_fibonacci_generator::next() {
for (;;) {
if (n_ > 4) {
uint64_t p = p_.next_prime();
for (; p > n_; ++n_)
next_fibonacci();
}
++n_;
big_int f = next_fibonacci();
if (is_probably_prime(f))
return {n_ - 1, f};
}
}
big_int prime_fibonacci_generator::next_fibonacci() {
big_int result = f0_;
big_int f = f0_ + f1_;
f0_ = f1_;
f1_ = f;
return result;
}
std::string to_string(const big_int& n) {
std::string str = n.get_str();
size_t len = str.size();
if (len > 40) {
str.replace(20, len - 40, "...");
str += " (";
str += std::to_string(len);
str += " digits)";
}
return str;
}
int main() {
auto start = std::chrono::high_resolution_clock::now();
prime_fibonacci_generator gen;
for (int i = 1; i <= 26; ++i) {
auto [n, f] = gen.next();
std::cout << i << ": F(" << n << ") = " << to_string(f) << '\n';
}
auto finish = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> ms(finish - start);
std::cout << "elapsed time: " << ms.count() << " seconds\n";
}
- Output:
1: F(3) = 2 2: F(4) = 3 3: F(5) = 5 4: F(7) = 13 5: F(11) = 89 6: F(13) = 233 7: F(17) = 1597 8: F(23) = 28657 9: F(29) = 514229 10: F(43) = 433494437 11: F(47) = 2971215073 12: F(83) = 99194853094755497 13: F(131) = 1066340417491710595814572169 14: F(137) = 19134702400093278081449423917 15: F(359) = 47542043773469822074...62268716376935476241 (75 digits) 16: F(431) = 52989271100609562179...55134424689676262369 (90 digits) 17: F(433) = 13872771278047838271...25954602593712568353 (91 digits) 18: F(449) = 30617199924845450305...49015933442805665949 (94 digits) 19: F(509) = 10597999265301490732...54396195769876129909 (107 digits) 20: F(569) = 36684474316080978061...15228143777781065869 (119 digits) 21: F(571) = 96041200618922553823...31637646183008074629 (119 digits) 22: F(2971) = 35710356064190986072...48642001438470316229 (621 digits) 23: F(4723) = 50019563612695729290...02854387700053591957 (987 digits) 24: F(5387) = 29304412869392580554...82040327194725855833 (1126 digits) 25: F(9311) = 34232086066590238613...37580645424669476289 (1946 digits) 26: F(9677) = 10565977873308861656...95169792504550670357 (2023 digits) elapsed time: 21.8042 seconds
CLU
fibonacci = iter () yields (int)
a: int := 1
b: int := 1
while true do
yield(a)
a, b := b, a+b
end
end fibonacci
prime = proc (n: int) returns (bool)
if n <= 4 then return(n=2 cor n=3) end
if n//2=0 cor n//3=0 then return(false) end
d: int := 5
while d*d <= n do
if n//d=0 then return(false) end
d := d+2
if n//d=0 then return(false) end
d := d+4
end
return(true)
end prime
start_up = proc ()
po: stream := stream$primary_output()
seen: int := 0
for n: int in fibonacci() do
if seen=9 then break end
if prime(n) then
stream$putl(po, int$unparse(n))
seen := seen+1
end
end
end start_up
- Output:
2 3 5 13 89 233 1597 28657 514229
COBOL
IDENTIFICATION DIVISION.
PROGRAM-ID. PRIME-FIBONACCI.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 FIBONACCI-VARS.
03 FIB PIC 9(6).
03 FIB-B PIC 9(6).
03 FIB-C PIC 9(6).
03 FIB-OUT PIC Z(5)9.
01 PRIME-VARS.
03 PRIME-FLAG PIC X.
88 PRIME VALUE 'X'.
03 DSOR PIC 9(4).
03 DSOR-SQ PIC 9(6).
03 DIV-RSLT PIC 9(6)V9(3).
03 FILLER REDEFINES DIV-RSLT.
05 FILLER PIC 9(6).
05 FILLER PIC 9(3).
88 DIVISIBLE VALUE ZERO.
PROCEDURE DIVISION.
BEGIN.
MOVE 1 TO FIB, FIB-B.
PERFORM FIND-PRIME-FIBONACCI 9 TIMES.
STOP RUN.
FIND-PRIME-FIBONACCI.
ADD FIB, FIB-B GIVING FIB-C.
MOVE FIB-B TO FIB.
MOVE FIB-C TO FIB-B.
PERFORM CHECK-PRIME.
IF NOT PRIME, GO TO FIND-PRIME-FIBONACCI.
MOVE FIB TO FIB-OUT.
DISPLAY FIB-OUT.
CHECK-PRIME SECTION.
BEGIN.
MOVE SPACE TO PRIME-FLAG.
IF FIB IS LESS THAN 5, GO TO TRIVIAL-PRIME.
DIVIDE FIB BY 2 GIVING DIV-RSLT.
IF DIVISIBLE, GO TO DONE.
DIVIDE FIB BY 3 GIVING DIV-RSLT.
IF DIVISIBLE, GO TO DONE.
MOVE 5 TO DSOR.
MOVE 25 TO DSOR-SQ.
MOVE 'X' TO PRIME-FLAG.
PERFORM TEST-DIVISOR
UNTIL NOT PRIME OR DSOR-SQ IS GREATER THAN FIB.
GO TO DONE.
TEST-DIVISOR.
DIVIDE FIB BY DSOR GIVING DIV-RSLT.
IF DIVISIBLE, MOVE SPACE TO PRIME-FLAG.
ADD 2 TO DSOR.
DIVIDE FIB BY DSOR GIVING DIV-RSLT.
IF DIVISIBLE, MOVE SPACE TO PRIME-FLAG.
ADD 4 TO DSOR.
MULTIPLY DSOR BY DSOR GIVING DSOR-SQ.
TRIVIAL-PRIME.
IF FIB IS EQUAL TO 2 OR 3, MOVE 'X' TO PRIME-FLAG.
DONE.
EXIT.
- Output:
2 3 5 13 89 233 1597 28657 514229
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
0040 d:=5
0050 WHILE d*d<=n DO
0060 IF n MOD d=0 THEN RETURN FALSE
0070 d:+2
0080 IF n MOD d=0 THEN RETURN FALSE
0090 d:+4
0100 ENDWHILE
0110 RETURN TRUE
0120 ENDFUNC prime
0130 //
0140 found:=0
0150 a:=1;b:=1
0160 WHILE found<9 DO
0170 IF prime(a) THEN
0180 PRINT a
0190 found:+1
0200 ENDIF
0210 c:=a+b;a:=b;b:=c
0220 ENDWHILE
0230 END
- Output:
2 3 5 13 89 233 1597 28657 514229
Cowgol
include "cowgol.coh";
sub prime(n: uint32): (p: uint8) is
p := 0;
if n <= 4 then
if n==2 or n==3 then
p := 1;
end if;
elseif n&1 != 0 and n%3 != 0 then
var d: uint32 := 5;
while d*d <= n loop
if n%d == 0 then return; end if;
d := d + 2;
if n%d == 0 then return; end if;
d := d + 4;
end loop;
p := 1;
end if;
end sub;
var a: uint32 := 1;
var b: uint32 := 1;
var n: uint8 := 0;
while n<9 loop
if prime(a) != 0 then
print_i32(a);
print_nl();
n := n+1;
end if;
var c := a + b;
a := b;
b := c;
end loop;
- Output:
2 3 5 13 89 233 1597 28657 514229
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;
- Output:
2 3 5 13 89 233 1597 28657 514229
Draco
proc nonrec prime(ulong n) bool:
bool comp;
ulong d;
if n <= 4 then n=2 or n=3
elif n&1 = 0 or n%3 = 0 then false
else
d := 5;
comp := false;
while not comp and d*d <= n do
if n%d = 0 then comp := true fi;
d := d + 2;
if n%d = 0 then comp := true fi;
d := d + 4
od;
not comp
fi
corp
proc nonrec main() void:
ulong a, b, c;
byte n;
a := 1;
b := 1;
n := 0;
while n < 9 do
if prime(a) then
writeln(a);
n := n + 1
fi;
c := a + b;
a := b;
b := c
od
corp
- Output:
2 3 5 13 89 233 1597 28657 514229
EasyLang
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
.
.
- Output:
2 3 5 13 89 233 1597 28657 514229
F#
// 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)
- 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 21->96041200618922553823942883360924865026104917411877067816822264789029014378308478864192589084185254331637646183008074629 22->357103560641909860720907774139063454445569926582843306794041997476301071102767570483343563518510007800304195444080518562630900027386498933944619210192856768352683468831754423234217978525765921040747291316681576556861490773135214861782877716560879686368266117365351884926393775431925116896322341130075880287169244980698837941931247516010101631704349963583400361910809925847721300802741705519412306522941202429437928826033885416656967971559902743150263252229456298992263008126719589203430407385228230361628494860172129702271172926469500802342608722006420745586297267929052509059154340968348509580552307148642001438470316229 23->500195636126957292905024512596972806695803345136243348970565288179435361313804956505581782637634612477979679893275103396147348650762007594937510804541145002304302867341006298493404319657382123201158007188252606550806694535329232256851056656372379649097735304781630173812454531781511107460619516018844320335033801984806819067802561370394036732654089838823551603083295670024453477589093119918386566397677610274213837391954591147603054442650326827980781140275941425217172428448698161710841740688042587204161256084914166762549007012713922172748259690566614580062682196606466498102571627683726718483229578044343646737694436406261444368327649097401550241341102704783841619376027737767077127010039900586625841991295111482539736725172169379740443890332234341104310470907449898415522414805210341138063350999730749950920147250683227798780264811215647706542511681027825390882770762662185410080310045261286851842669934849330548237271838345164232560544964315090365421726004108704302854387700053591957
Factor
USING: kernel lists lists.lazy math.primes prettyprint sequences ;
: prime-fib ( -- list )
{ 0 1 } [ [ rest ] [ sum suffix ] bi ] lfrom-by
[ second ] lmap-lazy [ prime? ] lfilter ;
9 prime-fib ltake [ . ] leach
- Output:
2 3 5 13 89 233 1597 28657 514229
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
- Output:
The first 10 prime Fibonacci numbers are: 2 3 5 13 89 233 1597 28657 514229 433494437
Go
package main
import "fmt"
func isPrime(n uint64) bool {
if n < 2 {
return false
}
if n%2 == 0 {
return n == 2
}
if n%3 == 0 {
return n == 3
}
d := uint64(5)
for d*d <= n {
if n%d == 0 {
return false
}
d += 2
if n%d == 0 {
return false
}
d += 4
}
return true
}
func main() {
f1 := uint64(1)
f2 := f1
count := 0
limit := 12 // as far as we can get without using big.Int
fmt.Printf("The first %d prime Fibonacci numbers are:\n", limit)
for count < limit {
f3 := f1 + f2
if isPrime(f3) {
fmt.Printf("%d ", f3)
count++
}
f1 = f2
f2 = f3
}
fmt.Println()
}
- Output:
The first 12 prime Fibonacci numbers are: 2 3 5 13 89 233 1597 28657 514229 433494437 2971215073 99194853094755497
J
Here, we pick a convenient expression and generate fibonacci numbers
fib=: <. 0.5 + (%:5) %~ (2 %~ 1+%:5)^i.63
Then we select the first 9 which are prime:
9 {. (#~ 1&p:) fib
2 3 5 13 89 233 1597 28657 514229
jq
Works with jq (*)
Works with gojq, the Go implementation of jq
See Erdős-primes#jq for a suitable definition of `is_prime` as used here.
(*) For unlimited precision integer arithmetic, use gojq.
# Emit an unbounded stream of Fibonacci numbers
def fibonaccis:
# input: [f(i-2), f(i-1)]
def fib: (.[0] + .[1]) as $sum
| if .[2] == 0 then $sum
else $sum, ([ .[1], $sum ] | fib)
end;
[-1, 1] | fib;
"The first 9 prime Fibonacci numbers are:",
limit(9; fibonaccis | select(is_prime))
- Output:
The first 9 prime Fibonacci numbers are: 2 3 5 13 89 233 1597 28657 514229
Java
Uses the PrimeGenerator class from Extensible prime generator#Java.
import java.math.BigInteger;
public class PrimeFibonacciGenerator {
private PrimeGenerator primeGen = new PrimeGenerator(10000, 200000);
private BigInteger f0 = BigInteger.ZERO;
private BigInteger f1 = BigInteger.ONE;
private int index = 0;
public static void main(String[] args) {
PrimeFibonacciGenerator gen = new PrimeFibonacciGenerator();
long start = System.currentTimeMillis();
for (int i = 1; i <= 26; ++i) {
BigInteger f = gen.next();
System.out.printf("%d: F(%d) = %s\n", i, gen.index - 1, toString(f));
}
long finish = System.currentTimeMillis();
System.out.printf("elapsed time: %g seconds\n", (finish - start)/1000.0);
}
private PrimeFibonacciGenerator() {
for (int i = 0; i < 2; ++i)
primeGen.nextPrime();
}
private BigInteger next() {
for (;;) {
if (index > 4) {
int p = primeGen.nextPrime();
for (; p > index; ++index)
nextFibonacci();
}
++index;
BigInteger f = nextFibonacci();
if (f.isProbablePrime(30))
return f;
}
}
private BigInteger nextFibonacci() {
BigInteger result = f0;
BigInteger f = f0.add(f1);
f0 = f1;
f1 = f;
return result;
}
private static String toString(BigInteger f) {
String str = f.toString();
if (str.length() > 40) {
StringBuilder s = new StringBuilder(str.substring(0, 20));
s.append("...");
s.append(str.substring(str.length() - 20));
s.append(" (");
s.append(str.length());
s.append(" digits)");
str = s.toString();
}
return str;
}
}
- Output:
1: F(3) = 2 2: F(4) = 3 3: F(5) = 5 4: F(7) = 13 5: F(11) = 89 6: F(13) = 233 7: F(17) = 1597 8: F(23) = 28657 9: F(29) = 514229 10: F(43) = 433494437 11: F(47) = 2971215073 12: F(83) = 99194853094755497 13: F(131) = 1066340417491710595814572169 14: F(137) = 19134702400093278081449423917 15: F(359) = 47542043773469822074...62268716376935476241 (75 digits) 16: F(431) = 52989271100609562179...55134424689676262369 (90 digits) 17: F(433) = 13872771278047838271...25954602593712568353 (91 digits) 18: F(449) = 30617199924845450305...49015933442805665949 (94 digits) 19: F(509) = 10597999265301490732...54396195769876129909 (107 digits) 20: F(569) = 36684474316080978061...15228143777781065869 (119 digits) 21: F(571) = 96041200618922553823...31637646183008074629 (119 digits) 22: F(2971) = 35710356064190986072...48642001438470316229 (621 digits) 23: F(4723) = 50019563612695729290...02854387700053591957 (987 digits) 24: F(5387) = 29304412869392580554...82040327194725855833 (1126 digits) 25: F(9311) = 34232086066590238613...37580645424669476289 (1946 digits) 26: F(9677) = 10565977873308861656...95169792504550670357 (2023 digits) elapsed time: 53.7480 seconds
Julia
using Lazy
using Primes
fibs = @lazy big"0":big"1":(fibs + drop(1, fibs))
primefibs = @>> fibs filter(isprime)
println(take(9, primefibs)) # List: (2 3 5 13 89 233 1597 28657 514229)
Mathematica /Wolfram Language
First solution by guessing some upper bound:
Select[Fibonacci /@ Range[100], PrimeQ, 9]
- Output:
{2, 3, 5, 13, 89, 233, 1597, 28657, 514229}
Second solution without guessing some upper bound:
list = {};
Do[
f = Fibonacci[i];
If[PrimeQ[f],
AppendTo[list, {i, f}];
If[Length[list] >= 26, Break[]]
]
,
{i, 1, \[Infinity]}
];
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}]
- Output:
1 F(3) = 2 2 F(4) = 3 3 F(5) = 5 4 F(7) = 13 5 F(11) = 89 6 F(13) = 233 7 F(17) = 1597 8 F(23) = 28657 9 F(29) = 514229 10 F(43) = 433494437 11 F(47) = 2971215073 12 F(83) = 99194 … 55497 (17 digits) 13 F(131) = 10663 … 72169 (28 digits) 14 F(137) = 19134 … 23917 (29 digits) 15 F(359) = 47542 … 76241 (75 digits) 16 F(431) = 52989 … 62369 (90 digits) 17 F(433) = 13872 … 68353 (91 digits) 18 F(449) = 30617 … 65949 (94 digits) 19 F(509) = 10597 … 29909 (107 digits) 20 F(569) = 36684 … 65869 (119 digits) 21 F(571) = 96041 … 74629 (119 digits) 22 F(2971) = 35710 … 16229 (621 digits) 23 F(4723) = 50019 … 91957 (987 digits) 24 F(5387) = 29304 … 55833 (1126 digits) 25 F(9311) = 34232 … 76289 (1946 digits) 26 F(9677) = 10565 … 70357 (2023 digits)
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)]]
- Output:
2 3 5 13 89 233 1597 28657 514229
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
- Output:
The first 9 prime Fibonacci numbers are: 2 3 5 13 89 233 1597 28657 514229
Oberon-07
MODULE PrimeFibonacciNumbers; (* show the first 9 prime fibonacci numbers *)
IMPORT Out, Math;
CONST toFind = 9;
VAR pCount, prev, curr, next :INTEGER;
(* returns true if n is prime, false otherwise - uses trial division *)
PROCEDURE isPrime( n :INTEGER ):BOOLEAN;
VAR i, rootN :INTEGER;
prime :BOOLEAN;
BEGIN
IF n < 3 THEN prime := n = 2
ELSIF ~ ODD( n ) THEN prime := FALSE
ELSE
prime := TRUE;
i := 3;
rootN := FLOOR( Math.sqrt( FLT( n ) ) );
WHILE ( i <= rootN ) & prime DO
prime := n MOD i # 0;
INC( i, 2 )
END
END
RETURN prime
END isPrime ;
BEGIN
pCount := 0;
prev := 0;
curr := 1;
WHILE pCount < toFind DO
next := prev + curr;
prev := curr;
curr := next;
IF isPrime( curr ) THEN
INC( pCount );
Out.String( " " );Out.Int( curr, 0 )
END
END
END PrimeFibonacciNumbers.
- Output:
2 3 5 13 89 233 1597 28657 514229
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
- Output:
2 3 5 13 89 233 1597 28657 514229
Perl
#!/usr/bin/perl
use strict; # https://rosettacode.org/wiki/First_9_Prime_Fibonacci_Number
use warnings;
use ntheory qw( is_prime );
my @first;
my $x = my $y = 1;
while( @first < 9 )
{
($x, $y) = ($x + $y, $x);
is_prime( $x ) and push @first, $x;
}
print "@first\n";
- Output:
2 3 5 13 89 233 1597 28657 514229
Phix
You can run this online here.
with javascript_semantics include mpfr.e integer n = 1, count=0 mpz f = mpz_init() atom t0 = time(), t1 = time()+1 while count<iff(platform()=JS?21:26) do integer fn = iff(n<4?n+2:get_prime(n)) mpz_fib_ui(f, fn) if mpz_prime(f) then count += 1 string e = elapsed(time()-t0) printf(1,"%2d: fib(%d) = %s (%s)\n",{count,fn,shorten(mpz_get_str(f)),e}) elsif platform()!=JS and time()>t1 then printf(1,"%d\r",fn) t1 = time()+1 end if n += 1 end while
- Output:
1: fib(3) = 2 (0s) 2: fib(4) = 3 (0.1s) 3: fib(5) = 5 (0.2s) 4: fib(7) = 13 (0.2s) 5: fib(11) = 89 (0.2s) 6: fib(13) = 233 (0.2s) 7: fib(17) = 1597 (0.2s) 8: fib(23) = 28657 (0.2s) 9: fib(29) = 514229 (0.2s) 10: fib(43) = 433494437 (0.2s) 11: fib(47) = 2971215073 (0.2s) 12: fib(83) = 99194853094755497 (0.2s) 13: fib(131) = 1066340417491710595814572169 (0.2s) 14: fib(137) = 19134702400093278081449423917 (0.2s) 15: fib(359) = 47542043773469822074...62268716376935476241 (75 digits) (0.2s) 16: fib(431) = 52989271100609562179...55134424689676262369 (90 digits) (0.2s) 17: fib(433) = 13872771278047838271...25954602593712568353 (91 digits) (0.2s) 18: fib(449) = 30617199924845450305...49015933442805665949 (94 digits) (0.2s) 19: fib(509) = 10597999265301490732...54396195769876129909 (107 digits) (0.2s) 20: fib(569) = 36684474316080978061...15228143777781065869 (119 digits) (0.2s) 21: fib(571) = 96041200618922553823...31637646183008074629 (119 digits) (0.2s) 22: fib(2971) = 35710356064190986072...48642001438470316229 (621 digits) (2.8s) 23: fib(4723) = 50019563612695729290...02854387700053591957 (987 digits) (14.0s) 24: fib(5387) = 29304412869392580554...82040327194725855833 (1,126 digits) (22.4s) 25: fib(9311) = 34232086066590238613...37580645424669476289 (1,946 digits) (2 minutes and 38s) 26: fib(9677) = 10565977873308861656...95169792504550670357 (2,023 digits) (3 minutes and 3s)
Pike
bool isPrime(int n) {
if (n < 2) {
return false;
}
if (!(n%2)) {
return n == 2;
}
if (!(n%3)) {
return n == 3;
}
int d = 5;
while(d*d <= n) {
if (!(n%d)) {
return false;
}
d += 2;
if (!(n%d)) {
return false;
}
d += 4;
}
return true;
}
int main() {
int limit = 12;
write("The first " + (string)limit + " prime Fibonacci numbers are:\n");
int count = 0;
int f1, f2;
f1 = f2 = 1;
while(count < limit) {
int f3 = f2 + f1;
if (isPrime(f3)) {
write((string)f3 + " ");
count = count + 1;
}
f1 = f2;
f2 = f3;
}
write("\n");
return 0;
}
- Output:
The first 12 prime Fibonacci numbers are: 2 3 5 13 89 233 1597 28657 514229 433494437 2971215073 99194853094755497
Python
2 things:
"""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.
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"""
def miller_rabin(n, k=5):
if n < 2:
return 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 format_large_number(n):
s = str(n)
if len(s) > 50:
return "%s...%s (Total %d digits)" % (s[:10], s[-10:], len(s))
return s
def prime_fibonacci(n):
a, b = 1, 1
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)
- Output:
fib(3): 2 (0.0 s) fib(4): 3 (0.0 s) fib(5): 5 (0.0 s) 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)
Quackery
isprime
is defined at Primality by trial division#Quackery.
1 1 []
[ dip [ tuck + ]
over isprime iff
[ over join
dup size 9 = ]
else false
until ]
echo 2drop
- Output:
[ 2 3 5 13 89 233 1597 28657 514229 ]
Raku
put ++$ .fmt("%2d: ") ~ $_ for (0, 1, * + * … *).grep( &is-prime )[^20];
- 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
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>>;
};
- Output:
2 3 5 13 89 233 1597 28657 514229
Ring
load "stdlibcore.ring"
see "working..." + nl
num = 0
see "The first 9 Prime Fibonacci numbers: " + nl
for n = 1 to 1000000
x = fib(n)
if isprime(x)
num++
if num< 10
? "" + 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
- Output:
working... The first 9 Prime Fibonacci numbers: 2 3 5 13 89 233 1597 28657 514229 done...
Rust
// [dependencies]
// rug = "1.15.0"
// primal = "0.3"
use rug::{Assign, Integer};
fn fibonacci() -> impl std::iter::Iterator<Item = Integer> {
let mut f0 = Integer::from(0);
let mut f1 = Integer::from(1);
std::iter::from_fn(move || {
let result = Integer::from(&f0);
let f = Integer::from(&f0 + &f1);
f0.assign(&f1);
f1.assign(&f);
Some(result)
})
}
fn prime_fibonacci() -> impl std::iter::Iterator<Item = (usize, Integer)> {
use rug::integer::IsPrime;
let mut primes = primal::Primes::all().skip(2);
let mut fib = fibonacci();
let mut n = 0;
std::iter::from_fn(move || loop {
if n > 4 {
let p = primes.next().unwrap();
while p > n {
fib.next();
n += 1;
}
}
n += 1;
if let Some(f) = fib.next() {
if f.is_probably_prime(30) != IsPrime::No {
return Some((n - 1, f));
}
}
})
}
fn to_string(num: &Integer) -> String {
let str = num.to_string();
let len = str.len();
if len > 40 {
let mut result = String::from(&str[..20]);
result.push_str("...");
result.push_str(&str[len - 20..]);
result.push_str(" (");
result.push_str(&len.to_string());
result.push_str(" digits)");
return result;
}
str
}
fn main() {
use std::time::Instant;
let now = Instant::now();
for (i, (n, f)) in prime_fibonacci().take(26).enumerate() {
println!("{}: F({}) = {}", i + 1, n, to_string(&f));
}
let time = now.elapsed();
println!("elapsed time: {} milliseconds", time.as_millis());
}
- Output:
1: F(3) = 2 2: F(4) = 3 3: F(5) = 5 4: F(7) = 13 5: F(11) = 89 6: F(13) = 233 7: F(17) = 1597 8: F(23) = 28657 9: F(29) = 514229 10: F(43) = 433494437 11: F(47) = 2971215073 12: F(83) = 99194853094755497 13: F(131) = 1066340417491710595814572169 14: F(137) = 19134702400093278081449423917 15: F(359) = 47542043773469822074...62268716376935476241 (75 digits) 16: F(431) = 52989271100609562179...55134424689676262369 (90 digits) 17: F(433) = 13872771278047838271...25954602593712568353 (91 digits) 18: F(449) = 30617199924845450305...49015933442805665949 (94 digits) 19: F(509) = 10597999265301490732...54396195769876129909 (107 digits) 20: F(569) = 36684474316080978061...15228143777781065869 (119 digits) 21: F(571) = 96041200618922553823...31637646183008074629 (119 digits) 22: F(2971) = 35710356064190986072...48642001438470316229 (621 digits) 23: F(4723) = 50019563612695729290...02854387700053591957 (987 digits) 24: F(5387) = 29304412869392580554...82040327194725855833 (1126 digits) 25: F(9311) = 34232086066590238613...37580645424669476289 (1946 digits) 26: F(9677) = 10565977873308861656...95169792504550670357 (2023 digits) elapsed time: 22642 milliseconds
RPL
≪ { } 0 1
WHILE 3 PICK SIZE 9 < REPEAT
SWAP OVER +
IF DUP ISPRIME? THEN ROT OVER + UNROT END
END DROP2
≫ 'TASK' STO
- Output:
1: { 2 3 5 13 89 233 1597 28657 514229 }
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)
- Output:
[2, 3, 5, 13, 89, 233, 1597, 28657, 514229]
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;
- Output:
2 3 5 13 89 233 1597 28657 514229
Sidef
say 12.by { .fib.is_prime }.map { .fib }
- Output:
[2, 3, 5, 13, 89, 233, 1597, 28657, 514229, 433494437, 2971215073, 99194853094755497]
Wren
import "./math" for Int
var limit = 11 // as far as we can go without using BigInt
System.print("The first %(limit) prime Fibonacci numbers are:")
var count = 0
var f1 = 1
var f2 = 1
while (count < limit) {
var f3 = f1 + f2
if (Int.isPrime(f3)) {
System.write("%(f3) ")
count = count + 1
}
f1 = f2
f2 = f3
}
System.print()
- Output:
The first 11 prime Fibonacci numbers are: 2 3 5 13 89 233 1597 28657 514229 433494437 2971215073
XPL0
func IsPrime(N); \Return 'true' if N is prime
int N, I;
[if N <= 2 then return N = 2;
if (N&1) = 0 then return false;
for I:= 3 to sqrt(N) do
[if rem(N/I) = 0 then return false;
I:= I+1;
];
return true;
];
int F, N, N0, C;
[C:= 0; N:= 1; N0:= 1;
loop [F:= N + N0;
if IsPrime(F) then
[IntOut(0, F); ChOut(0, ^ );
C:= C+1;
if C >= 9 then quit;
];
N0:= N;
N:= F;
];
]
- Output:
2 3 5 13 89 233 1597 28657 514229
Categories:
- Draft Programming Tasks
- 11l
- ABC
- Ada
- ALGOL 68
- ALGOL 68-primes
- ALGOL W
- Arturo
- AWK
- BASIC
- BASIC256
- FreeBASIC
- Gambas
- PureBasic
- Yabasic
- C
- C++
- GMP
- Primesieve
- CLU
- COBOL
- Comal
- Cowgol
- Delphi
- SysUtils,StdCtrls
- Draco
- EasyLang
- F Sharp
- Factor
- FutureBasic
- Go
- J
- Jq
- Java
- Julia
- Mathematica
- Wolfram Language
- Miranda
- Nim
- Oberon-07
- OCaml
- Perl
- Phix
- Phix/online
- Pike
- Python
- Quackery
- Raku
- Refal
- Ring
- Rust
- RPL
- Ruby
- SETL
- Sidef
- Wren
- Wren-math
- XPL0