Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
17
Task/Fibonacci-sequence/Pascal/fibonacci-sequence-1.pas
Normal file
17
Task/Fibonacci-sequence/Pascal/fibonacci-sequence-1.pas
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
function fib(n: integer):longInt;
|
||||
const
|
||||
Sqrt5 = sqrt(5.0);
|
||||
C1 = ln((Sqrt5+1.0)*0.5);//ln( 1.618..)
|
||||
//C2 = ln((1.0-Sqrt5)*0.5);//ln(-0.618 )) tsetsetse
|
||||
C2 = ln((Sqrt5-1.0)*0.5);//ln(+0.618 ))
|
||||
begin
|
||||
IF n>0 then
|
||||
begin
|
||||
IF odd(n) then
|
||||
fib := round((exp(C1*n) + exp(C2*n) )/Sqrt5)
|
||||
else
|
||||
fib := round((exp(C1*n) - exp(C2*n) )/Sqrt5)
|
||||
end
|
||||
else
|
||||
Fibdirekt := 0
|
||||
end;
|
||||
8
Task/Fibonacci-sequence/Pascal/fibonacci-sequence-2.pas
Normal file
8
Task/Fibonacci-sequence/Pascal/fibonacci-sequence-2.pas
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
function fib(n: integer): integer;
|
||||
begin
|
||||
if (n = 0) or (n = 1)
|
||||
then
|
||||
fib := n
|
||||
else
|
||||
fib := fib(n-1) + fib(n-2)
|
||||
end;
|
||||
22
Task/Fibonacci-sequence/Pascal/fibonacci-sequence-3.pas
Normal file
22
Task/Fibonacci-sequence/Pascal/fibonacci-sequence-3.pas
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
function fib(n: integer): integer;
|
||||
var
|
||||
f0, f1, tmpf0, k: integer;
|
||||
begin
|
||||
f1 := n;
|
||||
IF f1 >1 then
|
||||
begin
|
||||
k := f1-1;
|
||||
f0 := 0;
|
||||
f1 := 1;
|
||||
repeat
|
||||
tmpf0 := f0;
|
||||
f0 := f1;
|
||||
f1 := f1+tmpf0;
|
||||
dec(k);
|
||||
until k = 0;
|
||||
end
|
||||
else
|
||||
IF f1 < 0 then
|
||||
f1 := 0;
|
||||
fib := f1;
|
||||
end;
|
||||
4
Task/Fibonacci-sequence/Pascal/fibonacci-sequence-4.pas
Normal file
4
Task/Fibonacci-sequence/Pascal/fibonacci-sequence-4.pas
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
function FiboMax(n: integer):Extended; //maXbox
|
||||
begin
|
||||
result:= (pow((1+SQRT5)/2,n)-pow((1-SQRT5)/2,n))/SQRT5
|
||||
end;
|
||||
18
Task/Fibonacci-sequence/Pascal/fibonacci-sequence-5.pas
Normal file
18
Task/Fibonacci-sequence/Pascal/fibonacci-sequence-5.pas
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
function Fibo_BigInt(n: integer): string; //maXbox
|
||||
var tbig1, tbig2, tbig3: TInteger;
|
||||
begin
|
||||
result:= '0'
|
||||
tbig1:= TInteger.create(1); //temp
|
||||
tbig2:= TInteger.create(0); //result (a)
|
||||
tbig3:= Tinteger.create(1); //b
|
||||
for it:= 1 to n do begin
|
||||
tbig1.assign(tbig2)
|
||||
tbig2.assign(tbig3);
|
||||
tbig1.add(tbig3);
|
||||
tbig3.assign(tbig1);
|
||||
end;
|
||||
result:= tbig2.toString(false)
|
||||
tbig3.free;
|
||||
tbig2.free;
|
||||
tbig1.free;
|
||||
end;
|
||||
Loading…
Add table
Add a link
Reference in a new issue