Fibonacci en dash

#!/bin/dash

# fibonacci 1 => 1
# fibonacci 2 => 1
# f(n+2) = f(n+1) + f(n)
# f(n+3) = f(n+2) + f(n+1)
# f(3) = f(2) + f(1)
# f(4) = f(3) + f(2)
# f(n) = f(n-1) + f(n-2)

fibonacci(){        
if [ "$1" -eq 1 ] ;
 then
                echo 1
                return 0
        elif [ "$1" -eq 2 ] ;
 then 
               echo 1
                return 0

fi       

n1=`expr "$1" - 1 `
n2=`expr "$1" - 2 `        
fn1=`fibonacci "$n1" `        
fn2=`fibonacci "$n2" `        
expr "$fn1" + "$fn2"}
fibonacci "$1"
..... Lire la Suite

Read More