File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ # noglob creates problems because of '*' in input,
2+ # so we turn it off
3+ set -o noglob
4+
5+ # read our input line by line into an array
6+ mapfile -t arr
7+
8+ # find dimensions of puzzle
9+ width=${# arr}
10+ height=${# arr[@]} -1
11+ symbol_row=$height
12+
13+ for(( row= 0 ; row< width; ++ row))
14+ do
15+ # peek ahead at the symbols row
16+ next=${arr[symbol_row]: row: 2}
17+
18+ # gross hacks that make lots of warnings but work fine
19+ $next || operator=$_
20+
21+ # we set operator to '_' which is a placeholder for newline later
22+ ${next: 1} || operator=_
23+
24+ # loop over all the columns
25+ for(( col= 0 ; col< height; col++ ))
26+ do
27+ # print the number without a line break
28+ printf ${arr[col]: row: 1}
29+ done
30+
31+ # join the column with an operator
32+ printf $operator
33+ done \
34+ | sed ' s/. *_/+/g' \
35+ | sed ' s/$/0\n/' \
36+ | bc
You can’t perform that action at this time.
0 commit comments