Created
April 17, 2012 07:44
-
-
Save depressed-pho/2404239 to your computer and use it in GitHub Desktop.
Fibonacci series in /bin/sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
fibonacci_init() { | |
_fib_0=1 | |
_fib_1=1 | |
_fib_2=1 | |
_fib_n=0 | |
} | |
fibonacci_next() { | |
case $_fib_n in | |
0|1) | |
echo $_fib_2 | |
_fib_n=`expr $_fib_n + 1` | |
;; | |
*) | |
_fib_2=`expr $_fib_0 + $_fib_1` | |
echo $_fib_2 | |
_fib_0=$_fib_1 | |
_fib_1=$_fib_2 | |
;; | |
esac | |
} | |
fibonacci_init | |
while true; do | |
fibonacci_next | |
sleep 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment