+ day 2, part 2
This commit is contained in:
parent
3eb8fa522a
commit
34d173af62
9
02/README.md
Normal file
9
02/README.md
Normal 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
36
02/nyaa.sh
Executable 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"
|
Loading…
Reference in a new issue