langs a-z

This commit is contained in:
Ingy döt Net 2013-04-10 22:43:41 -07:00
parent db842d013d
commit d066446780
11389 changed files with 98361 additions and 1020 deletions

View file

@ -0,0 +1 @@
fibonocci(n)

View file

@ -0,0 +1,11 @@
fib(n)={
if(n<0,return((-1)^(n+1)*fib(n)));
my(a=0,b=1,t);
while(n,
t=a+b;
a=b;
b=t;
n--
);
a
};

View file

@ -0,0 +1 @@
fib(n)=my(k=0);while(n--,k++;while(!issquare(5*k^2+4)&&!issquare(5*k^2-4),k++));k

View file

@ -0,0 +1 @@
([1,1;1,0]^n)[1,2]

View file

@ -0,0 +1 @@
fib(n)=my(phi=(1+sqrt(5))/2);round((phi^n-phi^-n)/sqrt(5))

View file

@ -0,0 +1 @@
fib(n)=round(((1+sqrt(5))/2)^n/sqrt(5))

View file

@ -0,0 +1 @@
fib(n)=imag(quadgen(5)^n)

View file

@ -0,0 +1 @@
fib(n)=my(phi=quadgen(5));(phi^n-(-1/phi)^n)/(2*phi-1)

View file

@ -0,0 +1 @@
fib(n)=polcoeff(x/(1-x-x^2)+O(x^(n+1)),n)

View file

@ -0,0 +1,18 @@
fib(n)={
if(n<=0,
if(n,(-1)^(n+1)*fib(n),0)
,
my(v=lucas(n-1));
(2*v[1]+v[2])/5
)
};
lucas(n)={
if (!n, return([2,1]));
my(v=lucas(n >> 1), z=v[1], t=v[2], pr=v[1]*v[2]);
n=n%4;
if(n%2,
if(n==3,[v[1]*v[2]+1,v[2]^2-2],[v[1]*v[2]-1,v[2]^2+2])
,
if(n,[v[1]^2+2,v[1]*v[2]+1],[v[1]^2-2,v[1]*v[2]-1])
)
};

View file

@ -0,0 +1,11 @@
fib(n)={
if(n<2,
if(n<0,
(-1)^(n+1)*fib(n)
,
n
)
,
fib(n-1)+fib(n)
)
};