Instantly share code, notes, and snippets.

# markogresak/izziv3.sh

Created January 30, 2015 14:56
Show Gist options
• Save markogresak/176881366eb0406a1cb3 to your computer and use it in GitHub Desktop.
This file contains 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/bash function help { echo "Pomoc:" echo "Klic skripte: \$0 [ime_funkcije] [argument_funkcije]" echo "Moznosti:" echo -e "\t - fakrek = faktoriela z rekurzijo" echo -e "\t - fakiter = faktoriela z iteracijo" echo -e "\t - fibrek = fibonacci z rekurzijo" echo -e "\t - fibiter = fibonacci z iteracijo" } function fakrek { if (( \$1 <= 1 )); then echo 1 else tmp=\$(fakrek \$((\$1 - 1))) echo \$((\$1 * tmp)) fi } function fakiter { rez=1 for ((i=1; i<=\$1; i++ )); do rez=\$((\$rez * \$i)) done echo \$rez } function fibrek { i=\${1:-0} if (( \$1 <= 1 )); then echo \$i else echo \$(( \$(fibrek \$((\$i - 1))) + \$(fibrek \$((\$i - 2))) )) fi } function fibiter { rez=0 for ((i=1,c=0; c<\$1; i=rez - i, c++)); do rez=\$((\$rez + \$i)) done echo \$rez } arg=\${2:-10} case \$1 in (fakrek) fakrek \$arg ;; (fakiter) fakiter \$arg ;; (fibrek) fibrek \$arg ;; (fibiter) fibiter \$arg ;; (*) help \$arg ;; esac