aboutsummaryrefslogtreecommitdiff
path: root/challenge-003/abigail/bash/ch-2.sh
blob: ca5e5fb51052ef7900acf6d42b55ab2905686aa0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/sh

#
# See https://theweeklychallenge.org/blog/perl-weekly-challenge-003
#

#
# Run as: bash ch-2.sh < input-file
#

set -f

declare -A p

while read n
do   for ((row = 0; row <= n; row ++))
     do  p["$row;0"]=1
         printf "1 "
         for ((col = 1; col <= row; col ++))
         do  p["$row;$col"]=$((${p["$((row-1));$((col-1))"]:-0} + \
                               ${p["$((row-1));$col"]:-0}))
             printf "%d " ${p["$row;$col"]}
         done
         echo
     done
done