File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed
Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ FILE=" $1 "
4+
5+ CLEAN=" $( tr -s ' ' < " $FILE " \
6+ | sed ' s/^ //' ) "
7+
8+ COLS=$( echo " $CLEAN " | head -n1 | tr ' ' ' \n' | wc -l)
9+
10+ for (( i= 1 ;i<= COLS;++ i)) ; do
11+ (read operator; paste -sd$operator ) < <( echo " $CLEAN " | cut -d' ' -f$i | tac) | bc
12+ done | paste -sd+ | bc
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ set -o noglob
4+
5+ FILE=" $1 "
6+
7+ mapfile -t arr < $FILE
8+
9+ rows=${# arr[@]}
10+ op_row=$(( rows- 1 ))
11+ (( rows-- ))
12+
13+ cols=0
14+ for(( i= 0 ; i< rows; ++ i)) ; do
15+ len=" ${# arr[i]} "
16+ if [[ len -gt cols ]]; then
17+ cols=$len
18+ fi
19+ done
20+
21+ for(( r= 0 ; r<= cols; ++ r)) ; do
22+ new_op=${arr[op_row]: r: 1}
23+ if [[ -n $new_op && $new_op != ' ' ]]; then
24+ op=$new_op
25+ fi
26+ for(( c= 0 ; c< rows; c++ )) ; do
27+ echo -n " ${arr[c]: r: 1} "
28+ done
29+ echo $op
30+ done \
31+ | sed ' s/^[^0-9]*$//' \
32+ | tr ' \n' ' |' \
33+ | sed ' s/[+*]||/||/g;s/||/\n/g;s/|//g' \
34+ | bc | paste -sd+ | bc
You can’t perform that action at this time.
0 commit comments