-
Notifications
You must be signed in to change notification settings - Fork 0
/
day03.go
57 lines (48 loc) · 1.05 KB
/
day03.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
package main
func calcRucksack(lines []string) int {
var score int = 0
for _, v := range lines {
for i := 0; i < (len(v)/2)+1; i++ {
point := byte(v[i])
if occ := count(v[len(v)/2:], point); occ > 0 {
var multiplier int = 0
if point < byte('a') {
multiplier = int((point - byte('A'))) + 27
} else {
multiplier = int((point - byte('a'))) + 1
}
score += multiplier
break
}
}
}
return score
}
func calcRucksackOf3(lines []string) int {
var score int = 0
for i := 0; i < len(lines); i += 3 {
for line, j := lines[i], 0; j < len(line); j++ {
point := line[j]
if count(lines[i+1], point) > 0 && count(lines[i+2], point) > 0 {
var multiplier int = 0
if point < byte('a') {
multiplier = int((point - byte('A'))) + 27
} else {
multiplier = int((point - byte('a'))) + 1
}
score += multiplier
break
}
}
}
return score
}
func count(subject string, find byte) int {
var count int = 0
for i := 0; i < len(subject); i++ {
if subject[i] == find {
count++
}
}
return count
}