2021 Day 19 Part 2
This commit is contained in:
parent
7b389121b0
commit
0af5fe823c
1 changed files with 33 additions and 4 deletions
|
|
@ -15,12 +15,30 @@ func init() {
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
text := aoc.Input().ReadFile("day19.txt")
|
text := aoc.Input().ReadFile("day19.txt")
|
||||||
fmt.Println(part1(text))
|
scanners := parseInput(text)
|
||||||
|
offsets := placeScanners(scanners)
|
||||||
|
fmt.Println(part1(scanners, offsets))
|
||||||
|
fmt.Println(part2(offsets))
|
||||||
}
|
}
|
||||||
|
|
||||||
func part1(text string) int {
|
func part1(scanners map[int]Scanner, offsets map[int]Offset) int {
|
||||||
scanners := parseInput(text)
|
return uniqPoints(scanners, offsets)
|
||||||
|
}
|
||||||
|
|
||||||
|
func part2(offsets map[int]Offset) (max int) {
|
||||||
|
for i := 0; i < len(offsets)-1; i++ {
|
||||||
|
for j := i + 1; j < len(offsets); j++ {
|
||||||
|
si, sj := offsets[i], offsets[j]
|
||||||
|
distance := si.tx.minus(sj.tx).manhattan()
|
||||||
|
if distance > max {
|
||||||
|
max = distance
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func placeScanners(scanners map[int]Scanner) map[int]Offset {
|
||||||
offsets := make(map[int]Offset)
|
offsets := make(map[int]Offset)
|
||||||
offsets[0] = Offset{tx: V{0, 0, 0}, rot: noRot}
|
offsets[0] = Offset{tx: V{0, 0, 0}, rot: noRot}
|
||||||
|
|
||||||
|
|
@ -46,7 +64,7 @@ solve:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return uniqPoints(scanners, offsets)
|
return offsets
|
||||||
}
|
}
|
||||||
|
|
||||||
type Offset struct {
|
type Offset struct {
|
||||||
|
|
@ -151,6 +169,17 @@ func (v V) rot(r R) V {
|
||||||
return rot(r, v)
|
return rot(r, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v V) manhattan() int {
|
||||||
|
return abs(v.x) + abs(v.y) + abs(v.z)
|
||||||
|
}
|
||||||
|
|
||||||
|
func abs(n int) int {
|
||||||
|
if n < 0 {
|
||||||
|
return -n
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
type R struct {
|
type R struct {
|
||||||
xx, xy, xz int
|
xx, xy, xz int
|
||||||
yx, yy, yz int
|
yx, yy, yz int
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue