First 9 prime Fibonacci number: Difference between revisions
m
syntax highlighting fixup automation
m (Added Algol W) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 5:
=={{header|Ada}}==
<
procedure Prime_Fibonacci is
Line 51:
end if;
end loop;
end Prime_Fibonacci;</
{{out}}
<pre>
Line 67:
=={{header|ALGOL 68}}==
{{libheader|ALGOL 68-primes}}
<
PR read "primes.incl.a68" PR # include prime utilities #
INT p count := 0;
Line 82:
FI
OD
END</
{{out}}
<pre>
Line 89:
=={{header|ALGOL W}}==
<
% -- returns true if n is prime, false otherwise - uses trial division %
Line 120:
end while_pCount_lt_9
end task
end.</
{{out}}
<pre>
Line 127:
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f FIRST_9_PRIME_FIBONACCI_NUMBER.AWK
BEGIN {
Line 158:
return(1)
}
</syntaxhighlight>
{{out}}
<pre>
Line 168:
=={{header|BASIC}}==
==={{header|BASIC256}}===
<
if v < 2 then return False
if v mod 2 = 0 then return v = 2
Line 200:
end if
end while
end</
{{out}}
<pre>
Line 207:
==={{header|FreeBASIC}}===
<
If ValorEval <= 1 Then Return False
For i As Integer = 2 To Int(Sqr(ValorEval))
Line 235:
End If
Loop
Sleep</
{{out}}
<pre>The first 9 Prime Fibonacci numbers:
Line 241:
==={{header|PureBasic}}===
<
If v <= 1 : ProcedureReturn #False
ElseIf v < 4 : ProcedureReturn #True
Line 285:
PrintN(#CRLF$ + "--- terminado, pulsa RETURN---"): Input()
CloseConsole()
EndIf</
{{out}}
<pre>
Line 292:
==={{header|Yabasic}}===
<
if v < 2 then return False : fi
if mod(v, 2) = 0 then return v = 2 : fi
Line 324:
end if
loop
end</
{{out}}
<pre>
Line 334:
{{trans|Wren}}
Requires C99 or later.
<
#include <stdint.h>
#include <stdbool.h>
Line 367:
printf("\n");
return 0;
}</
{{out}}
Line 378:
{{libheader|GMP}}
{{libheader|Primesieve}}
<
#include <iostream>
#include <sstream>
Line 451:
std::chrono::duration<double> ms(finish - start);
std::cout << "elapsed time: " << ms.count() << " seconds\n";
}</
{{out}}
Line 485:
=={{header|CLU}}==
<
a: int := 1
b: int := 1
Line 518:
end
end
end start_up</
{{out}}
<pre>2
Line 531:
=={{header|COBOL}}==
<
PROGRAM-ID. PRIME-FIBONACCI.
Line 594:
IF FIB IS EQUAL TO 2 OR 3, MOVE 'X' TO PRIME-FLAG.
DONE.
EXIT.</
{{out}}
<pre> 2
Line 607:
=={{header|Comal}}==
<
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 629:
0210 c:=a+b;a:=b;b:=c
0220 ENDWHILE
0230 END</
{{out}}
<pre>
Line 643:
=={{header|Cowgol}}==
<
sub prime(n: uint32): (p: uint8) is
Line 676:
a := b;
b := c;
end loop;</
{{out}}
<pre>2
Line 689:
=={{header|Draco}}==
<
bool comp;
ulong d;
Line 723:
b := c
od
corp</
{{out}}
<pre>2
Line 736:
=={{header|F_Sharp|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)
</syntaxhighlight>
{{out}}
<pre>
Line 769:
=={{header|Factor}}==
{{works with|Factor|0.99 2021-06-02}}
<
: prime-fib ( -- list )
Line 775:
[ second ] lmap-lazy [ prime? ] lfilter ;
9 prime-fib ltake [ . ] leach</
{{out}}
<pre>
Line 791:
=={{header|Go}}==
{{trans|C}}
<
import "fmt"
Line 835:
}
fmt.Println()
}</
{{out}}
Line 847:
Here, we pick a convenient expression and [https://code.jsoftware.com/wiki/Essays/Fibonacci_Sequence generate fibonacci numbers]
<
Then we select the first 9 which are prime:
<
2 3 5 13 89 233 1597 28657 514229</
=={{header|jq}}==
Line 863:
(*) For unlimited precision integer arithmetic, use gojq.
<
def fibonaccis:
# input: [f(i-2), f(i-1)]
Line 873:
"The first 9 prime Fibonacci numbers are:",
limit(9; fibonaccis | select(is_prime))</
{{out}}
<pre>
Line 890:
=={{header|Java}}==
Uses the PrimeGenerator class from [[Extensible prime generator#Java]].
<
public class PrimeFibonacciGenerator {
Line 949:
return str;
}
}</
{{out}}
Line 983:
=={{header|Julia}}==
<
using Primes
Line 991:
println(take(9, primefibs)) # List: (2 3 5 13 89 233 1597 28657 514229)
</syntaxhighlight>
=={{header|Mathematica}}/{{header|Wolfram Language}}==
First solution by guessing some upper bound:
<
{{out}}
<pre>{2, 3, 5, 13, 89, 233, 1597, 28657, 514229}</pre>
Second solution without guessing some upper bound:
<
Do[
f = Fibonacci[i];
Line 1,011:
];
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}]</
{{out}}
<pre>1 F(3) = 2
Line 1,041:
=={{header|Perl}}==
<
use strict; # https://rosettacode.org/wiki/First_9_Prime_Fibonacci_Number
Line 1,054:
is_prime( $x ) and push @first, $x;
}
print "@first\n";</
{{out}}
<pre>
Line 1,063:
{{libheader|Phix/online}}
You can run this online [http://phix.x10.mx/p2js/primefib.htm here].
<!--<
<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 1,082:
<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>
<!--</
{{out}}
<pre>
Line 1,115:
=={{header|Pike}}==
{{trans|C}}
<
if (n < 2) {
return false;
Line 1,161:
write("\n");
return 0;
}</
{{out}}
<pre>The first 12 prime Fibonacci numbers are:
Line 1,167:
=={{header|Python}}==
<
print("working...")
print("The firsr 9 Prime Fibonacci numbers:")
Line 1,199:
print()
print("done...")
</syntaxhighlight>
{{out}}
<pre>
Line 1,210:
=={{header|Raku}}==
<syntaxhighlight lang="raku"
{{out}}
<pre> 1: 2
Line 1,234:
=={{header|Ring}}==
<
load "stdlibcore.ring"
see "working..." + nl
Line 1,258:
if nr = 1 return 1 ok
if nr > 1 return fib(nr-1) + fib(nr-2) ok
</syntaxhighlight>
{{out}}
<pre>
Line 1,268:
=={{header|Rust}}==
<
// rug = "1.15.0"
// primal = "0.3"
Line 1,331:
let time = now.elapsed();
println!("elapsed time: {} milliseconds", time.as_millis());
}</
{{out}}
Line 1,365:
=={{header|Sidef}}==
<
{{out}}
<pre>
Line 1,373:
=={{header|Wren}}==
{{libheader|Wren-math}}
<
var limit = 11 // as far as we can go without using BigInt
Line 1,389:
f2 = f3
}
System.print()</
{{out}}
Line 1,398:
=={{header|XPL0}}==
<
int N, I;
[if N <= 2 then return N = 2;
Line 1,420:
N:= F;
];
]</
{{out}}
|