+ day 2, part 2

meow
Dominique Liberda 2022-12-03 00:54:52 -05:00
parent 3eb8fa522a
commit 34d173af62
2 changed files with 45 additions and 0 deletions

9
02/README.md Normal file
View File

@ -0,0 +1,9 @@
# Day 2
"i like how simple the if structure looks like here!"
`cat data | ./meow.sh`
"oh no. my if structure."
`cat data | ./nyaa.sh`

36
02/nyaa.sh Executable file
View File

@ -0,0 +1,36 @@
#!/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" == 2 ]]; then
score=$((score+3+opp))
elif [[ "$you" == 1 && "$opp" == 1 ]]; then
score=$((score+3))
elif [[ "$you" == 1 && "$opp" == 2 ]]; then
score=$((score+1))
elif [[ "$you" == 1 && "$opp" == 3 ]]; then
score=$((score+2))
elif [[ "$you" == 3 && "$opp" == 1 ]]; then
score=$((score+6+2))
elif [[ "$you" == 3 && "$opp" == 2 ]]; then
score=$((score+6+3))
elif [[ "$you" == 3 && "$opp" == 3 ]]; then
score=$((score+6+1))
fi
done
echo "$score"