-
Notifications
You must be signed in to change notification settings - Fork 0
/
2.sh
executable file
·78 lines (73 loc) · 2.23 KB
/
2.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
total_one=0
round_one=0
total_two=0
round_two=0
while read line; do
read -r opponent myself <<< $(echo $line)
case $opponent in
'A') # Rock
case $myself in
'X') # 1. Rock
round_one=$((1+3))
# 2. lose
round_two=$((3+0)) # choose scissors to lose
;;
'Y') # 1. Paper
round_one=$((2+6))
# 2. draw
round_two=$((1+3)) # choose rock to draw
;;
'Z') # 1. Scissors
round_one=$((3+0))
# 2. win
round_two=$((2+6)) # choose paper to win
;;
esac
;;
'B') # Paper
case $myself in
'X') # 1. Rock
round_one=$((1+0))
# 2. lose
round_two=$((1+0)) # choose rock to lose
;;
'Y') # 1. Paper
round_one=$((2+3))
# 2. draw
round_two=$((2+3)) # choose paper to draw
;;
'Z') # 1. Scissors
round_one=$((3+6))
# 2. win
round_two=$((3+6)) # choose scissors to win
;;
esac
;;
'C') # Scissors
case $myself in
'X') # 1. Rock
round_one=$((1+6))
# 2. lose
round_two=$((2+0)) # choose paper to lose
;;
'Y') # 1. Paper
round_one=$((2+0))
# 2. draw
round_two=$((3+3)) # choose scissors to draw
;;
'Z') # 1. Scissors
round_one=$((3+3))
# 2. win
round_two=$((1+6)) # choose rock to win
;;
esac
;;
esac
total_one=$(($total_one + $round_one))
total_two=$(($total_two + $round_two))
round_one=0
round_two=0
done < $1
echo Part One: $total_one
echo Part Two: $total_two