File tree 1 file changed +36
-12
lines changed
1 file changed +36
-12
lines changed Original file line number Diff line number Diff line change 7
7
)
8
8
9
9
func main () {
10
- // read file and load caloriesPerElf
10
+ // read file and load games
11
11
dat , err := os .ReadFile ("input.txt" )
12
12
if err != nil {
13
13
panic (err )
@@ -24,28 +24,52 @@ func main() {
24
24
fmt .Printf ("total score is %d" , totalScore )
25
25
}
26
26
27
- var scores map [string ]int = map [string ]int {
28
- "X" : 1 ,
29
- "Y" : 2 ,
30
- "Z" : 3 ,
27
+ func getWinningMove (opp string ) int {
28
+ if opp == "A" {
29
+ return 2
30
+ }
31
+ if opp == "B" {
32
+ return 3
33
+ }
34
+ return 1
35
+ }
36
+
37
+ func getLosingMove (opp string ) int {
38
+ if opp == "A" {
39
+ return 3
40
+ }
41
+ if opp == "B" {
42
+ return 1
43
+ }
44
+ return 2
45
+ }
46
+
47
+ func getDrawMove (opp string ) int {
48
+ if opp == "A" {
49
+ return 1
50
+ }
51
+ if opp == "B" {
52
+ return 2
53
+ }
54
+ return 3
31
55
}
32
56
33
57
func calculateGame (g []string ) int {
34
58
// A B C
35
59
opp := g [0 ]
36
- // X Y Z
37
- me := g [1 ]
60
+ // X - Lose; Y - Draw; Z - Win
61
+ outcome := g [1 ]
38
62
39
63
// Win condition
40
- if opp == "A" && me == "Y" || opp == "B" && me == "Z" || opp == "C" && me == "X " {
41
- return 6 + scores [ me ]
64
+ if outcome == "Z " {
65
+ return 6 + getWinningMove ( opp )
42
66
}
43
67
44
68
// Loss condition
45
- if opp == "A" && me == "Z" || opp == "B" && me == "X" || opp == "C" && me == "Y " {
46
- return scores [ me ]
69
+ if outcome == "X " {
70
+ return getLosingMove ( opp )
47
71
}
48
72
49
73
// Draw condition
50
- return 3 + scores [ me ]
74
+ return 3 + getDrawMove ( opp )
51
75
}
You can’t perform that action at this time.
0 commit comments