-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday25.go
More file actions
120 lines (98 loc) · 3.03 KB
/
day25.go
File metadata and controls
120 lines (98 loc) · 3.03 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package main
import (
"fmt"
"flag"
)
// Used to build a work list of water sources to be followed
type spaceCoordsStruct struct {
xCoord int
yCoord int
zCoord int
tCoord int
constellation int
}
// func: constellationsControlA
//
func constellationsControlA(fileName string, maxRange int, debug bool) (int) {
var pointLocation []spaceCoordsStruct
var constellationCounter int = 0
var tempDistance int
var tempConstellation1, tempConstellation2 int = 0, 0
var countingStars[1000] bool
fileContents, _ := readLines(fileName)
pointLocation = processInputFile(fileContents)
if debug {
fmt.Println(pointLocation)
}
for i := 0; i < len(pointLocation) - 1; i++ {
if pointLocation[i].constellation == 0 {
constellationCounter++
pointLocation[i].constellation = constellationCounter
}
for j := i+1; j < len(pointLocation); j++ {
if debug {
fmt.Println("================================")
fmt.Println("First PointLocation:", i, pointLocation[i])
fmt.Println("Second PointLocation:", j, pointLocation[j])
}
tempDistance = manhattanDistance4D(pointLocation[i], pointLocation[j])
if debug {
fmt.Printf("Distance from %d to %d is %d\n", i, j, tempDistance)
}
if tempDistance <= maxRange {
tempConstellation1 = pointLocation[i].constellation
tempConstellation2 = pointLocation[j].constellation
if tempConstellation2 == 0 {
pointLocation[j].constellation = tempConstellation1
} else {
if tempConstellation1 == tempConstellation2 {
// Do nothing. Already in the same constellation
} else {
if debug {
fmt.Println("Joining Constellations")
}
for z := 0; z < len(pointLocation); z++ {
if pointLocation[z].constellation == tempConstellation2 {
pointLocation[z].constellation = tempConstellation1
}
}
}
}
}
}
}
if debug {
fmt.Println(pointLocation)
}
// Now need to count the number of unique consellations we have. We need to do this as joining constellations together
// can leave us with a non-contiguous list of constellations
for i := 0; i < len(pointLocation); i++ {
//fmt.Println("Constellation:", pointLocation[i].constellation)
countingStars[pointLocation[i].constellation] = true
}
constellationCounter = 0
for i := 0; i < len(countingStars); i++ {
if countingStars[i] {
constellationCounter++
}
}
return constellationCounter
}
// Main routine
func main() {
var debug bool
var maxRange int
fileNamePtr := flag.String("file", "input1.txt", "A filename containing input strings")
flag.BoolVar(&debug, "debug", false, "turns print debugging on")
flag.IntVar(&maxRange, "range", 3, "Range to count as constellation")
execPartPtr := flag.String("part", "a", "Which part of day18 do you want to calc (a or b)")
flag.Parse()
switch *execPartPtr {
case "a":
fmt.Println("Part a - Number of constelations:", constellationsControlA(*fileNamePtr, maxRange, debug))
case "b":
fmt.Println("Not here yet")
default:
fmt.Println("Bad part choice. Available choices are 'a' and 'b'")
}
}