Data update
This commit is contained in:
parent
35bcdeebf8
commit
74c69a0df6
2427 changed files with 31826 additions and 3468 deletions
21
Task/Fibonacci-sequence/BootBASIC/fibonacci-sequence.basic
Normal file
21
Task/Fibonacci-sequence/BootBASIC/fibonacci-sequence.basic
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
10 print "Enter a ";
|
||||
20 print "number ";
|
||||
30 print "greater ";
|
||||
40 print "than 1";
|
||||
50 print " and less";
|
||||
60 print " than 25";
|
||||
70 input z
|
||||
80 b=1
|
||||
90 a=0
|
||||
100 n=2
|
||||
110 f=a+b
|
||||
120 a=b
|
||||
130 b=f
|
||||
140 n=n+1
|
||||
150 if n-z-1 goto 110
|
||||
160 print "The ";
|
||||
170 print z ;
|
||||
180 print "th ";
|
||||
190 print "Fibonacci ";
|
||||
200 print "Number is ";
|
||||
210 print f
|
||||
|
|
@ -1 +1 @@
|
|||
fibN=: (-&2 +&$: -&1)^:(1&<) M."0
|
||||
fibN=: (-&2 +&$: <:)^:(1&<) M."0
|
||||
|
|
|
|||
|
|
@ -1,4 +1 @@
|
|||
fibN 12
|
||||
144
|
||||
fibN i.31
|
||||
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040
|
||||
fibN=: [: {."1 +/\@|.@]^:[&0 1
|
||||
|
|
|
|||
4
Task/Fibonacci-sequence/J/fibonacci-sequence-3.j
Normal file
4
Task/Fibonacci-sequence/J/fibonacci-sequence-3.j
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
fibN 12
|
||||
144
|
||||
fibN i.31
|
||||
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040
|
||||
62
Task/Fibonacci-sequence/Pascal/fibonacci-sequence-6.pas
Normal file
62
Task/Fibonacci-sequence/Pascal/fibonacci-sequence-6.pas
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
program Fibonacci_console;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses SysUtils;
|
||||
|
||||
function Fibonacci( n : word) : uint64;
|
||||
{
|
||||
Starts with the pair F[0],F[1]. At each iteration, uses the doubling formulae
|
||||
to pass from F[k],F[k+1] to F[2k],F[2k+1]. If the current bit of n (starting
|
||||
from the high end) is 1, there is a further step to F[2k+1],F[2k+2].
|
||||
}
|
||||
var
|
||||
marker, half_n : word;
|
||||
f, g : uint64; // pair of consecutive Fibonacci numbers
|
||||
t, u : uint64; // -----"-----
|
||||
begin
|
||||
// The values of F[0], F[1], F[2] are assumed to be known
|
||||
case n of
|
||||
0 : result := 0;
|
||||
1, 2 : result := 1;
|
||||
else begin
|
||||
half_n := n shr 1;
|
||||
marker := 1;
|
||||
while marker <= half_n do marker := marker shl 1;
|
||||
|
||||
// First time: current bit is 1 by construction,
|
||||
// so go straight from F[0],F[1] to F[1],F[2].
|
||||
f := 1; // = F[1]
|
||||
g := 1; // = F[2]
|
||||
marker := marker shr 1;
|
||||
|
||||
while marker > 1 do begin
|
||||
t := f*(2*g - f);
|
||||
u := f*f + g*g;
|
||||
if (n and marker = 0) then begin
|
||||
f := t;
|
||||
g := u;
|
||||
end
|
||||
else begin
|
||||
f := u;
|
||||
g := t + u;
|
||||
end;
|
||||
marker := marker shr 1;
|
||||
end;
|
||||
|
||||
// Last time: we need only one of the pair.
|
||||
if (n and marker = 0) then
|
||||
result := f*(2*g - f)
|
||||
else
|
||||
result := f*f + g*g;
|
||||
end; // end else (i.e. n > 2)
|
||||
end; // end case
|
||||
end;
|
||||
|
||||
// Main program
|
||||
var
|
||||
n : word;
|
||||
begin
|
||||
for n := 0 to 93 do
|
||||
WriteLn( SysUtils.Format( 'F[%2u] = %20u', [n, Fibonacci(n)]));
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue