Skip to content

Commit 76edb31

Browse files
committed
unminify it
1 parent bff4735 commit 76edb31

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

2025/day06/p2-golf-unmin.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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

0 commit comments

Comments
 (0)