#!/bin/bash

while read b h d ndig target
do
  hd=$((h+d))
  b1=$((b-1))
  x=$((d-ndig))
  if [[ $x -gt $b1 ]]
  then
    x=$b1
  fi
  err=$((target-x))
  printf "%3d%3d%3d%3d%3d  %3d%3d%3d\n" $b $h $d $ndig $hd $target $x $err
# echo $b $h $d $ndig $hd      $target $x $err
done <t1.asc
exit
  b  h  d ndig target
  7  3  4 -2  6
  7  4  3 -2  5
  6  4  2 -2  4
  8  4  4 -2  6
  7  4  4 -2  6
  6  4  4 -2  5
  5  4  4 -2  4
  4  4  4 -2  3
  3  4  4 -2  2
  7  4  3 -3  6
  7  4  3 -2  5
  6  4  2 -3  5
  8  4  4 -3  7
  7  4  4 -3  6
  6  4  4 -3  5
