From 89db74bfa53063dd4670f14cbf4d46f29ee77d33 Mon Sep 17 00:00:00 2001 From: bdnugget Date: Mon, 8 Dec 2025 14:48:53 +0100 Subject: [PATCH] Day 2 part 1 soln --- 02/poop.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/02/poop.sh b/02/poop.sh index 9e1c592..8b8ac5a 100755 --- a/02/poop.sh +++ b/02/poop.sh @@ -4,7 +4,9 @@ trap 'echo "SHIEEEET at line $LINENO" >&2' ERR main() { local line - line=$(< example.txt) + local sum=0 + # line=$(< example.txt) + line=$(< input.txt) IFS=',' read -ra ranges <<< "$line" @@ -12,9 +14,19 @@ main() { IFS='-' read -r start end <<< "$r" for ((i=start; i<=end; i++)); do - echo "$i" + if (( ${#i} % 2 == 0 )); then + left="${i:0:${#i}/2}" + right="${i:${#i}/2}" + + if [[ "$left" == "$right" ]]; then + echo "Match: $i" + ((sum+=$i)) + fi + fi done done + + echo "Sum: $sum" } main "$@"