mirror of
https://github.com/bdnugget/aoc_bash.git
synced 2026-11-07 04:37:27 +00:00
Day 2 part 1 soln
This commit is contained in:
1 parent
80272b3747
commit
89db74bfa5
1 file changed
+14
-2
+14
-2
@@ -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 "$@"
|
||||
Reference in new issue
Block a user