-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday23.go
More file actions
128 lines (104 loc) · 3.92 KB
/
day23.go
File metadata and controls
128 lines (104 loc) · 3.92 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
121
122
123
124
125
126
127
128
package main
import (
"fmt"
"flag"
)
// Used to build a work list of water sources to be followed
type nanoCoordsStruct struct {
xCoord int
yCoord int
zCoord int
signalRange int
}
// func: nanoBotControlB
//
func nanoBotControlB(fileName string, debug bool) (int) {
var nanoBotLocation []nanoCoordsStruct
var minX, maxX, minY, maxY, minZ, maxZ int
var botsInRange, tempDistance int = 0, 0
var maxBotsInRange, maxArrayPos int = 0, 0
fileContents, _ := readLines(fileName)
nanoBotLocation = processInputFile(fileContents)
minX, maxX, minY, maxY, minZ, maxZ = scanInputForMaxMins(nanoBotLocation)
if debug {
fmt.Printf("minX: %d maxX: %d minY: %d maxY: %d minZ: %d maxZ: %d\n", minX, maxX, minY, maxY, minZ, maxZ)
}
for i := 0; i < len(nanoBotLocation); i++ {
botsInRange = 0
for j := 0; j < len(nanoBotLocation); j++ {
tempDistance = manhattanDistance(nanoBotLocation[j], nanoBotLocation[i])
//if tempDistance <= nanoBotLocation[i].signalRange {
if tempDistance <= 50000000 {
botsInRange++
}
}
if debug {
if botsInRange > 300 {
fmt.Printf("Bot at %d,%d,%d range %d has %d bots in range\n", nanoBotLocation[i].xCoord, nanoBotLocation[i].yCoord, nanoBotLocation[i].zCoord, nanoBotLocation[i].signalRange, botsInRange)
}
}
if botsInRange > maxBotsInRange {
maxArrayPos = i
fmt.Printf("High Number found at pos: %d Bots: %d\n", maxArrayPos, botsInRange)
maxBotsInRange = botsInRange
}
}
fmt.Println("Max bots:", nanoBotLocation[maxArrayPos], maxBotsInRange)
// Need to do some thinking here. How can we work out what is close?
// Basically we're looking for the intersection of the most number of nanobots
// If you take the coords of a nanobot and the signal range it desribes a "circular" area of space
// Where the most intersections between nanobot circles happens is our answer
//
// So how do I build a model of all the circles and work out what intersects what?
// Perhaps build a circle for point [i] then compare against all the other points' circles, counting intersections (and where they are)
// at the end of it I should have an idea of roughly where the most intersections happened, then I can walk through each of the
// points in the intersection area and test them all specifically against the nanobots
return 0
}
// func: nanoBotControl-A
//
func nanoBotControlA(fileName string, debug bool) (int) {
var nanoBotLocation []nanoCoordsStruct
var mostPowerfulPos, mostPowerfulRange int // Array reference to the most powerful nanoBot
var botsInRange int = 0
var tempDistance int
fileContents, _ := readLines(fileName)
nanoBotLocation = processInputFile(fileContents)
if debug {
fmt.Println(nanoBotLocation)
}
mostPowerfulPos = findMostPowerful(nanoBotLocation)
mostPowerfulRange = nanoBotLocation[mostPowerfulPos].signalRange
if debug {
fmt.Println("Most powerful nanobot is at:", mostPowerfulPos)
}
for i := 0; i < len(nanoBotLocation); i++ {
tempDistance = manhattanDistance(nanoBotLocation[mostPowerfulPos], nanoBotLocation[i])
if tempDistance <= mostPowerfulRange {
botsInRange++
}
if debug {
fmt.Printf("Nano %d,%d,%d is %d distance away\n", nanoBotLocation[i].xCoord, nanoBotLocation[i].yCoord, nanoBotLocation[i].zCoord, tempDistance)
}
}
if debug {
fmt.Println("Bots in range:", botsInRange)
}
return botsInRange
}
// Main routine
func main() {
var debug bool
fileNamePtr := flag.String("file", "input1.txt", "A filename containing input strings")
flag.BoolVar(&debug, "debug", false, "turns print debugging on")
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 nanobots in range:", nanoBotControlA(*fileNamePtr, debug))
case "b":
fmt.Println("Part b - Distance from best position to 0,0,0:", nanoBotControlB(*fileNamePtr, debug))
default:
fmt.Println("Bad part choice. Available choices are 'a' and 'b'")
}
}