-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
67 lines (56 loc) · 1.01 KB
/
main.go
File metadata and controls
67 lines (56 loc) · 1.01 KB
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
package main
import (
"github.com/danvolchek/AdventOfCode/lib"
"strings"
)
type round struct {
opponent, you string
}
func parse(line string) round {
parts := strings.Split(line, " ")
return round{
opponent: toTerm(parts[0]),
you: toTerm(parts[1]),
}
}
func toTerm(line string) string {
switch line {
case "A", "X":
return "R"
case "B", "Y":
return "P"
case "C", "Z":
return "S"
default:
panic(line)
}
}
func solve(lines []round) int {
score := 0
for _, line := range lines {
win := line.you == "R" && line.opponent == "S" || line.you == "P" && line.opponent == "R" || line.you == "S" && line.opponent == "P"
tie := line.you == line.opponent
switch line.you {
case "R":
score += 1
case "P":
score += 2
case "S":
score += 3
}
if win {
score += 6
} else if tie {
score += 3
}
}
return score
}
func main() {
solver := lib.Solver[[]round, int]{
ParseF: lib.ParseLine(parse),
SolveF: solve,
}
solver.Expect("A Y\nB X\nC Z", 15)
solver.Verify(8933)
}