-
Notifications
You must be signed in to change notification settings - Fork 0
/
day_three_part_one.go
67 lines (54 loc) · 1.29 KB
/
day_three_part_one.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
// 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")
line := fileScanner.Text()
itemCount := len(line)
firstComp := string(line[0:(itemCount / 2)])
secondComp := string(line[(itemCount / 2):itemCount])
fmt.Println(firstComp + " " + secondComp)
//chFirstComp := firstComp.toCharArray();
//chSecondComp := secondComp.toCharArray();
result := make(map[string]string)
for i := range firstComp {
for j := range secondComp {
if firstComp[i] == secondComp[j] {
result[string(firstComp[i])] = string(firstComp[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 result {
fmt.Println("equal ", result[i])
fmt.Println("equal ", prios[result[i]])
total += prios[result[i]]
}
fmt.Println("current total ", total)
}
fmt.Println("total ", total)
readFile.Close()
}