Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
4
Task/Fibonacci-sequence/FunL/fibonacci-sequence-1.funl
Normal file
4
Task/Fibonacci-sequence/FunL/fibonacci-sequence-1.funl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
def
|
||||
fib( 0 ) = 0
|
||||
fib( 1 ) = 1
|
||||
fib( n ) = fib( n - 1 ) + fib( n - 2 )
|
||||
7
Task/Fibonacci-sequence/FunL/fibonacci-sequence-2.funl
Normal file
7
Task/Fibonacci-sequence/FunL/fibonacci-sequence-2.funl
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
def fib( n ) =
|
||||
def
|
||||
_fib( 0, prev, _ ) = prev
|
||||
_fib( 1, _, next ) = next
|
||||
_fib( n, prev, next ) = _fib( n - 1, next, next + prev )
|
||||
|
||||
_fib( n, 0, 1 )
|
||||
6
Task/Fibonacci-sequence/FunL/fibonacci-sequence-3.funl
Normal file
6
Task/Fibonacci-sequence/FunL/fibonacci-sequence-3.funl
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
val fib =
|
||||
def _fib( a, b ) = a # _fib( b, a + b )
|
||||
|
||||
_fib( 0, 1 )
|
||||
|
||||
println( fib(10000) )
|
||||
7
Task/Fibonacci-sequence/FunL/fibonacci-sequence-4.funl
Normal file
7
Task/Fibonacci-sequence/FunL/fibonacci-sequence-4.funl
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
def fib( n ) =
|
||||
a, b = 0, 1
|
||||
|
||||
for i <- 1..n
|
||||
a, b = b, a+b
|
||||
|
||||
a
|
||||
5
Task/Fibonacci-sequence/FunL/fibonacci-sequence-5.funl
Normal file
5
Task/Fibonacci-sequence/FunL/fibonacci-sequence-5.funl
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import math.sqrt
|
||||
|
||||
def fib( n ) =
|
||||
phi = (1 + sqrt( 5 ))/2
|
||||
int( (phi^n - (-phi)^-n)/sqrt(5) + .5 )
|
||||
19
Task/Fibonacci-sequence/FunL/fibonacci-sequence-6.funl
Normal file
19
Task/Fibonacci-sequence/FunL/fibonacci-sequence-6.funl
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
def mul( a, b ) =
|
||||
res = array( a.length(), b(0).length() )
|
||||
|
||||
for i <- 0:a.length(), j <- 0:b(0).length()
|
||||
res( i, j ) = sum( a(i, k)*b(k, j) | k <- 0:b.length() )
|
||||
|
||||
vector( res )
|
||||
|
||||
def
|
||||
pow( _, 0 ) = ((1, 0), (0, 1))
|
||||
pow( x, 1 ) = x
|
||||
pow( x, n )
|
||||
| 2|n = pow( mul(x, x), n\2 )
|
||||
| otherwise = mul(x, pow( mul(x, x), (n - 1)\2 ) )
|
||||
|
||||
def fib( n ) = pow( ((0, 1), (1, 1)), n )(0, 1)
|
||||
|
||||
for i <- 0..10
|
||||
println( fib(i) )
|
||||
Loading…
Add table
Add a link
Reference in a new issue