2018 Day 23*
Had to find someone else's python solution to get an answer. Need to pull it apart and figure out what's wrong with my solution.
This commit is contained in:
31
2018/day23/bots.go
Normal file
31
2018/day23/bots.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type Bots map[Coordinate][]int
|
||||
|
||||
func NewBots(input []string) Bots {
|
||||
m := make(Bots)
|
||||
for _, data := range input {
|
||||
var r int
|
||||
var c Coordinate
|
||||
_, err := fmt.Sscanf(data, "pos=<%d,%d,%d>, r=%d", &c.X, &c.Y, &c.Z, &r)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
m[c] = append(m[c], r)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func (m Bots) HaveInRange(pos Coordinate) int {
|
||||
var sum int
|
||||
for c, rs := range m {
|
||||
for _, r := range rs {
|
||||
if pos.Distance(c) <= r {
|
||||
sum++
|
||||
}
|
||||
}
|
||||
}
|
||||
return sum
|
||||
}
|
||||
Reference in New Issue
Block a user