Skip to content

Commit 2595547

Browse files
committed
commit before golf
1 parent 4e8cc3b commit 2595547

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

2025/day06/p1.sh

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

2025/day06/p2.sh

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

0 commit comments

Comments
 (0)