Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
18
Task/Pascals-triangle/UNIX-Shell/pascals-triangle.sh
Normal file
18
Task/Pascals-triangle/UNIX-Shell/pascals-triangle.sh
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#! /bin/bash
|
||||
pascal() {
|
||||
local -i n=${1:-1}
|
||||
if (( n <= 1 )); then
|
||||
echo 1
|
||||
else
|
||||
local output=$( $FUNCNAME $((n - 1)) )
|
||||
set -- $( tail -n 1 <<<"$output" ) # previous row
|
||||
echo "$output"
|
||||
printf "1 "
|
||||
while [[ -n $1 ]]; do
|
||||
printf "%d " $(( $1 + ${2:-0} ))
|
||||
shift
|
||||
done
|
||||
echo
|
||||
fi
|
||||
}
|
||||
pascal "$1"
|
||||
Loading…
Add table
Add a link
Reference in a new issue