-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
75 lines (66 loc) · 1.09 KB
/
main.go
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
package main
import (
"fmt"
"io"
"os"
"strings"
"github.com/devries/advent_of_code_2022/utils"
"github.com/spf13/pflag"
)
const inputfile = "../inputs/day02.txt"
func main() {
pflag.Parse()
f, err := os.Open(inputfile)
utils.Check(err, "error opening input")
defer f.Close()
r := solve(f)
fmt.Println(r)
}
func solve(r io.Reader) int {
lines := utils.ReadLines(r)
points := 0
for _, ln := range lines {
hands := strings.Fields(ln)
switch hands[1] {
case "X":
// Lose round
switch hands[0] {
case "A":
// rock v scissors
points += 3
case "B":
// paper v rock
points += 1
case "C":
// scissors v paper
points += 2
}
case "Y":
// Draw round pick same as other player
points += 3
switch hands[0] {
case "A":
points += 1
case "B":
points += 2
case "C":
points += 3
}
case "Z":
// Win round
points += 6
switch hands[0] {
case "A":
// rock v paper
points += 2
case "B":
// paper v scissors
points += 3
case "C":
// scissors v rock
points += 1
}
}
}
return points
}