adventofcode/2018/day23/bots.go
Brian Buller 1ec6280623 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.
2019-11-07 15:43:14 -06:00

32 lines
501 B
Go

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
}