Skip to main content

Math - Pascal Triangle

BASH

#!/bin/bash

row=1
while [[ $row -le 47 ]]; do
  printf "%03d: " $row
  for (( col=$row; col > 0; col-- )); do
    if [[ ${col} -eq 1 ]]; then
      cell[${col}]=1
    elif [[ ${col} -eq ${row} ]]; then
      cell[${col}]=1
    else
      cell[${col}]=$(( ${cell[${col}-1]}+${cell[${col}]} ))
    fi
  done
  for (( col=1; col <= ${row}; col++ )); do
    printf "%15d " ${cell[${col}]}
  done
  echo
  row=$((row+1))
done


Comments

Popular posts from this blog

TV Series - The Brokenwood Mysteries [NZ] (2014) - Season 10

 

Movie - Sin City: A Dame to Kill For (2014)

 

Movies - Deadpool & Wolverine (2024)