-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaoc2202.go
86 lines (74 loc) · 1.14 KB
/
aoc2202.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
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"fmt"
"bufio"
"os"
"strings"
_ "io/ioutil"
_ "strconv"
)
func solve(path string) (int, int) {
data, err := os.Open(path)
if err != nil {
panic(err)
}
var a [][]string
scanner := bufio.NewScanner(data)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
temp := strings.Split(scanner.Text(), " ")
a = append(a, temp)
}
// solve
res := 0
rr := 0
res2 := 0
d := map[string]int {
"A": 1, "B": 2, "C": 3,
"X": 1, "Y": 2, "Z": 3,
}
for _, line := range a {
l, r := d[line[0]], d[line[1]]
// part 1
if l == r {
res += r + 3
} else {
res += r
rr = l + 1
if rr > 3 {
rr = 1
}
if rr == r {
res += 6
}
}
// part 2
if r == 2 {
res2 += l + 3
} else if r == 1 {
l -= 1
if l < 1 {
l = 3
}
res2 += l
} else {
l += 1
if l > 3 {
l = 1
}
res2 += l + 6
}
}
return res, res2
}
func main() {
var r1, r2 int
r1, r2 = solve("_inputs/2202.0")
fmt.Println("data")
fmt.Println("Star 1:", r1)
fmt.Println("Star 2:", r2, "\n")
r1, r2 = solve("_inputs/2202.1")
fmt.Println("test")
fmt.Println("Star 1:", r1)
fmt.Println("Star 2:", r2)
}