+ day 2, part 1

meow
Dominique Liberda 2022-12-03 00:43:54 -05:00
parent 19c4e6238b
commit 3eb8fa522a
1 changed files with 31 additions and 0 deletions

31
02/meow.sh Executable file
View File

@ -0,0 +1,31 @@
#!/bin/bash
# a, x - rock 1
# b, y - paper 2
# c, z - scissors 3
function normaliz() {
[[ $1 =~ [AX] ]] && echo 1
[[ $1 =~ [BY] ]] && echo 2
[[ $1 =~ [CZ] ]] && echo 3
}
score=0
while read line; do
you=$(normaliz ${line/* /})
opp=$(normaliz ${line/ */})
if [[ "$you" == "$opp" ]]; then
score=$((score+3))
elif [[ "$you" == 1 && "$opp" == 3 ]]; then
score=$((score+6))
elif [[ "$you" == 2 && "$opp" == 1 ]]; then
score=$((score+6))
elif [[ "$you" == 3 && "$opp" == 2 ]]; then
score=$((score+6))
fi
score=$((score+you))
done
echo "$score"