-
Notifications
You must be signed in to change notification settings - Fork 0
/
day_three_part_two.go
70 lines (57 loc) · 1.33 KB
/
day_three_part_two.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
// advent_of_code project main.go
package main
import (
"bufio"
"fmt"
"os"
//"strings"
)
func main() {
fmt.Println("Hello World!")
readFile, err := os.Open("day_three_input.txt")
if err != nil {
fmt.Println(err)
}
fileScanner := bufio.NewScanner(readFile)
fileScanner.Split(bufio.ScanLines)
total := 0
for fileScanner.Scan() {
fmt.Println("next backpack")
backpackOne := fileScanner.Text()
fileScanner.Scan()
backpackTwo := fileScanner.Text()
fileScanner.Scan()
backpackThree := fileScanner.Text()
fmt.Println(backpackOne)
fmt.Println(backpackTwo)
fmt.Println(backpackThree)
fmt.Println("\n")
badgeItems := make(map[string]string)
for i := range backpackOne {
for j := range backpackTwo {
for k := range backpackThree {
if backpackOne[i] == backpackTwo[j] && backpackTwo[j] == backpackThree[k] {
badgeItems[string(backpackOne[i])] = string(backpackOne[i])
}
}
}
}
prios := make(map[string]int)
counter := 1
for i := 'a'; i <= 'z'; i++ {
prios[string(i)] = counter
counter++
}
for i := 'A'; i <= 'Z'; i++ {
prios[string(i)] = counter
counter++
}
for i := range badgeItems {
fmt.Println("equal ", badgeItems[i])
fmt.Println("equal prio ", prios[badgeItems[i]])
total += prios[badgeItems[i]]
}
fmt.Println("total ", total)
}
readFile.Close()
}