D2P1 in ysh

This commit is contained in:
Abdulkadir Furkan Şanlı
2023-12-10 13:00:08 +01:00
parent 9d4b066535
commit 8679c5766f
5 changed files with 112 additions and 56 deletions

View File

@@ -1,13 +1,13 @@
#!/usr/bin/env bash
#set -o errexit
set -o errexit
set -o nounset
#set -o pipefail
set -o pipefail
if [[ "${TRACE-0}" == "1" ]]; then
set -o xtrace
fi
cd "$(dirname "$0")"
INPUT=$1
main ()
{
@@ -20,9 +20,10 @@ main ()
IFS=';' read -r -a sets <<< "${stripped_game}"
for (( i=0; i<${#sets[@]}; i++ )); do
for color in "${colors[@]}"; do
count=$(grep -o "[0-9]* ${color}" <<< "${sets[$i]}" | grep -o '[0-9]*')
count=$(grep -o "[0-9]* ${color}" <<< "${sets[$i]}" | grep -o '[0-9]*' || true)
if [[ $count -gt ${limits[$color]} ]]; then
possible=false
break 2
fi
done
done
@@ -30,7 +31,7 @@ main ()
id=$(grep -o '[0-9]*' <<< "${game}" | head -n 1)
possible_ids+=($id)
fi
done < input.txt
done < "${INPUT}"
declare -i sum=0
for id in "${possible_ids[@]}"; do
(( sum+=id ))