#!/bin/bash
#
# fileName: yanghui.sh
# author: liAng
# mail: angl6112@163.com
# created: Thu 12 Jan 2023 10:56:59 AM CST
#
### BEGIN INIT INFO
# Description:
# 1.输入行数, 打印杨辉三角形
#
### END INIT INFO
COLUMNS=$(tput cols)
function worker() {
read -p '输入高度: ' line
arr=(0 1)
for ((i=1;i<=$line;i++))
do
for ((a=0;a<$i;a++))
do
if [ "$a" -eq 0 ];then res[0]=1; continue; fi
if [ "$a" -eq "$[$i-1]" ];then res[$i]=1; continue; fi
let b=$a-1
x=${arr[$a]}
y=${arr[$b]}
res[$a]=$[$x+$y]
done
unset arr; arr=(${res[*]})
title=`echo ${res[*]}`
printf "%*s\n" $(((${#title}+$COLUMNS)/2)) "$title"
unset res
done
}
function main() {
worker
}
main