From 68ccdaaaddf5882e44b86cb803a77e49ee28ff4c Mon Sep 17 00:00:00 2001 From: kirbylife Date: Tue, 3 Dec 2024 00:47:17 -0600 Subject: [PATCH] Day 3 part 1 --- day-3/script.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 day-3/script.sh diff --git a/day-3/script.sh b/day-3/script.sh new file mode 100644 index 0000000..899a8b9 --- /dev/null +++ b/day-3/script.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +regex="mul\(([0-9]{1,3}),([0-9]{0,3}))" + +acc=0 +while read line; do + if [[ $line =~ $regex ]] then + n1=${BASH_REMATCH[1]} + n2=${BASH_REMATCH[2]} + acc=$(expr $n1 \* $n2 + $acc) + fi +done <<< $(grep -Eo $regex input.txt) +echo $acc