@@ -8,77 +8,101 @@ import (
8
8
9
9
func main () {
10
10
var score int
11
+ //test := []string{
12
+ // "A Y",
13
+ // "B X",
14
+ // "C Z",
15
+ //}
16
+
11
17
for _ , round := range loadInput () {
18
+
12
19
shapes := strings .Split (round , " " )
13
- me := getValue (shapes [1 ])
14
-
15
- if (shapes [0 ] == "A" && shapes [1 ] == "X" ) ||
16
- (shapes [0 ] == "B" && shapes [1 ] == "Y" ) ||
17
- (shapes [0 ] == "C" && shapes [1 ] == "Z" ) {
18
- // draw = 3
19
- log .Printf ("[DRAW] score(%v) + draw(3) + shape(%v)" , score , me )
20
- score = score + DRAW + me
21
- } else if (shapes [0 ] == "A" && shapes [1 ] == "Y" ) ||
22
- (shapes [0 ] == "B" && shapes [1 ] == "Z" ) ||
23
- (shapes [0 ] == "C" && shapes [1 ] == "X" ) {
24
- // win = 6
25
- log .Printf ("[WIN] score(%v) + win(6) + shape(%v)" , score , me )
26
- score = score + WIN + me
27
- } else if (shapes [0 ] == "A" && shapes [1 ] == "Z" ) ||
28
- (shapes [0 ] == "B" && shapes [1 ] == "X" ) ||
29
- (shapes [0 ] == "C" && shapes [1 ] == "Y" ) {
30
- // lose = 0
31
- log .Printf ("[LOSE] score(%v) + lose(0) + shape(%v)" , score , me )
32
- score = score + LOSE + me
20
+
21
+ elfKey := shapes [0 ]
22
+ outcomeKey := shapes [1 ]
23
+ if elfKey == "A" && outcomeKey == DRAW {
24
+ // ROCK(A) vs DRAW(Y=3) = ROCK(A=1)
25
+ score = score + drawInt + 1
26
+ }
27
+
28
+ if elfKey == "B" && outcomeKey == LOSE {
29
+ // PAPER(B) vs LOSE(X=0) = ROCK(A=1)
30
+ score = score + loseInt + 1
31
+ }
32
+
33
+ if elfKey == "C" && outcomeKey == WIN {
34
+ // SCISSORS(C) vs WIN(Z=6) = ROCK(A=1)
35
+ score = score + winInt + 1
36
+ }
37
+
38
+ if elfKey == "B" && outcomeKey == DRAW {
39
+ // PAPER(B) vs DRAW(Y=3) = PAPER(B=2)
40
+ score = score + drawInt + 2
41
+ }
42
+
43
+ if elfKey == "C" && outcomeKey == LOSE {
44
+ // SCISSORS(C) vs LOSE(X=0) = PAPER(B=2)
45
+ score = score + loseInt + 2
46
+ }
47
+
48
+ if elfKey == "A" && outcomeKey == WIN {
49
+ // ROCK(A) vs WIN(Z=6) = PAPER(B=2)
50
+ score = score + winInt + 2
51
+ }
52
+
53
+ if elfKey == "C" && outcomeKey == DRAW {
54
+ // SCISSORS(C) vs DRAW(Y=3) = SCISSORS(C=3)
55
+ score = score + drawInt + 3
33
56
}
57
+
58
+ if elfKey == "A" && outcomeKey == LOSE {
59
+ // ROCK(A) vs LOSE(X=0) = SCISSORS(C=3)
60
+ score = score + loseInt + 3
61
+ }
62
+
63
+ if elfKey == "B" && outcomeKey == WIN {
64
+ // PAPER(B) vs WIN(Z=6) = SCISSORS(C=3)
65
+ score = score + winInt + 3
66
+ }
67
+
34
68
}
35
69
log .Println ("score:" , score ) // 15632
36
70
}
37
71
38
72
func getValue (shape string ) int {
39
73
switch shape {
40
- case "A" , "X" :
74
+ case "A" :
41
75
return 1
42
- case "B" , "Y" :
76
+ case "B" :
43
77
return 2
44
- case "C" , "Z" :
78
+ case "C" :
45
79
return 3
80
+ // WIN = 6 // Z
81
+ // DRAW = 3 // Y
82
+ // LOSE = 0 // X
46
83
default :
47
84
log .Fatalln ("[ERROR] unknown shape:" , shape )
48
85
return 0
49
86
}
50
87
}
51
88
52
- // rock vs rock = draw
53
- // rock vs paper = lose
54
- // rock vs scissors = win
55
-
56
- // paper vs paper = draw
57
- // paper vs scissors = lose
58
- // paper vs rock = win
59
-
60
- // scissors vs scissors = draw
61
- // scissors vs rock = lose
62
- // scissors vs paper = win
63
-
64
- /////////////////////////////////
65
-
66
- // A vs X = draw
67
- // B vs Y = draw
68
- // C vs Z = draw
69
-
70
- // A vs Y = win
71
- // B vs Z = win
72
- // C vs X = win
73
-
74
- // A vs Z = lose
75
- // B vs X = lose
76
- // C vs Y = lose
89
+ ///////////////////////////////////
77
90
78
91
const (
79
- WIN = 6
80
- DRAW = 3
81
- LOSE = 0
92
+ WIN = "Z" // 6 // Z
93
+ DRAW = "Y" // 3 // Y
94
+ LOSE = "X" // 0 // X
95
+ winInt = 6 // Z
96
+ drawInt = 3 // Y
97
+ loseInt = 0 // X
98
+ )
99
+
100
+ var (
101
+ outcomes = map [string ]int {
102
+ "Z" : 6 ,
103
+ "Y" : 3 ,
104
+ "X" : 0 ,
105
+ }
82
106
)
83
107
84
108
////////////////////
0 commit comments