-
Notifications
You must be signed in to change notification settings - Fork 0
/
3b.go
52 lines (45 loc) · 780 Bytes
/
3b.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"
"os"
"strings"
)
func check(e error) {
if e != nil {
panic(e)
}
}
func main() {
dat, err := os.ReadFile("3.txt")
check(err)
data := string(dat)
rows := strings.Split(data, "\n")
var m map[rune]int
points := 0
for rowIndex,row := range rows {
firstRow := rowIndex % 3 == 0
tmp := make(map[rune]bool)
if firstRow == true {
m = make(map[rune]int)
}
for _,char := range row {
// only increase value if not already increased for this row
if tmp[char] != true {
m[char] += 1
}
tmp[char] = true
}
for k,v := range m {
if v == 3 {
var val int
if k >= 97 && k < 123 {
val = int(k) - 97 + 1
} else {
val = int(k) - 65 + 27
}
points += val
}
}
}
fmt.Println(points)
}