-
Notifications
You must be signed in to change notification settings - Fork 17
/
day02_2.go
68 lines (56 loc) · 954 Bytes
/
day02_2.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
package main
import (
"bufio"
"fmt"
"log"
"os"
"strings"
)
func day2_2_score(left, right string) int {
total := 0
switch left {
case "A": // Rock
switch right {
case "X": // Lose
total += 3 + 0
case "Y": // Draw
total += 1 + 3
case "Z": // Win
total += 2 + 6
}
case "B": // Paper
switch right {
case "X": // Lose
total += 1 + 0
case "Y": // Draw
total += 2 + 3
case "Z": // Win
total += 3 + 6
}
case "C": // Scissors
switch right {
case "X": // Lose
total += 2 + 0
case "Y": // Draw
total += 3 + 3
case "Z": // Win
total += 1 + 6
}
}
return total
}
func day2_2() {
file, err := os.Open("day02_2.input")
if err != nil {
log.Fatal(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
total := 0
for scanner.Scan() {
fields := strings.Fields(scanner.Text())
left, right := fields[0], fields[1]
total += day2_2_score(left, right)
}
fmt.Println(total)
}