aboutsummaryrefslogtreecommitdiff
path: root/2025/06/puzzle-2.sh
diff options
context:
space:
mode:
Diffstat (limited to '2025/06/puzzle-2.sh')
-rwxr-xr-x2025/06/puzzle-2.sh27
1 files changed, 27 insertions, 0 deletions
diff --git a/2025/06/puzzle-2.sh b/2025/06/puzzle-2.sh
new file mode 100755
index 0000000..cba270f
--- /dev/null
+++ b/2025/06/puzzle-2.sh
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+{
+ printf '('
+ for i in $(seq "$(head -n1 input | wc -c)")
+ do
+ num="$(cut -c $i input | paste -sd '')"
+ num="${num%${num##*[![:space:]]}}"
+
+ case "$num" in
+ *[+*])
+ test -n "$op" && printf ') + ('
+ op="${num#${num%?}}"
+ num="${num%?}"
+ printf '%d %s ' $num "$op"
+ ;;
+ '')
+ test "$op" = +
+ printf '%d' $?
+ ;;
+ *)
+ printf '%d %s ' $num "$op"
+ ;;
+ esac
+ done
+ printf ')\n'
+} | bc