aoc/2023/1/1/solution.sh
2023-12-09 16:01:06 +01:00

27 lines
447 B
Bash
Executable File

#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
if [[ "${TRACE-0}" == "1" ]]; then
set -o xtrace
fi
INPUT=$1
main ()
{
declare -a components
declare -i result=0
while read -r line; do
mapfile -t matches <<< "$(grep -o '[[:digit:]]' <<< "${line}")"
components+=("${matches[0]}${matches[-1]}")
done < "${INPUT}"
for value in "${components[@]}"; do
(( result += value ))
done
echo "${result}"
}
main