-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
52 lines (45 loc) · 882 Bytes
/
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
package main
import (
"fmt"
"strings"
"unicode"
"github.com/devkvlt/aoc"
)
func main() {
lines := aoc.Lines("input")
// Part 1
var total1 int
for _, line := range lines {
var common rune
first := line[:len(line)/2]
second := line[len(line)/2:]
for _, item := range first {
if strings.ContainsRune(second, item) {
common = item
}
}
total1 += priority(common)
}
fmt.Println(total1)
// Part 2
var total2 int
for i := 0; i < len(lines); i += 3 {
var common rune
first := lines[i]
second := lines[i+1]
third := lines[i+2]
for _, item := range first {
if strings.ContainsRune(second, item) && strings.ContainsRune(third, item) {
common = item
}
}
total2 += priority(common)
}
fmt.Println(total2)
}
func priority(item rune) int {
if unicode.IsLower(item) {
return int(item - 'a' + 1)
}
return int(item - 'A' + 27)
}