More work on 2021 day 19
This commit is contained in:
parent
9bc3b7300b
commit
3bf29e69ae
@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
@ -12,21 +11,29 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
inp := h.StdinToStringSlice()
|
inp := h.StdinToStringSlice()
|
||||||
scanners := parseScanners(inp)
|
scanners := parseScanners(inp)
|
||||||
|
part1(scanners)
|
||||||
|
}
|
||||||
|
|
||||||
|
func part1(scanners []scanner) {
|
||||||
foundBeacons := scanners[0].beacons
|
foundBeacons := scanners[0].beacons
|
||||||
foundScannerPositions := []beacon{{0, 0, 0}}
|
foundScannerPositions := []beacon{{0, 0, 0}}
|
||||||
|
|
||||||
remaining := scanners[1:]
|
remaining := scanners[1:]
|
||||||
for len(remaining) > 0 {
|
for len(remaining) > 0 {
|
||||||
|
fmt.Println(len(remaining), "Remaining")
|
||||||
var wrk scanner
|
var wrk scanner
|
||||||
wrk, remaining = remaining[0], remaining[1:]
|
wrk, remaining = remaining[0], remaining[1:]
|
||||||
s := NewScanner(foundBeacons).getScannerFromOverlap(wrk)
|
s, err := NewScanner(foundBeacons).getTransformedIfOverlap(wrk)
|
||||||
if s == nil {
|
if err != nil {
|
||||||
remaining = append(remaining, s)
|
remaining = append(remaining, wrk)
|
||||||
} else {
|
} else {
|
||||||
foundBeacons = append(foundBeacons, s.beacons...)
|
foundBeacons = append(foundBeacons, s.beacons...)
|
||||||
//foundScannerPositions = append(foundScannerPositions,
|
foundScannerPositions = append(foundScannerPositions, s.position)
|
||||||
}
|
}
|
||||||
|
fmt.Println(" ", foundBeacons)
|
||||||
}
|
}
|
||||||
|
fmt.Println("# Part 1")
|
||||||
|
fmt.Println(len(foundScannerPositions))
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseScanners(inp []string) []scanner {
|
func parseScanners(inp []string) []scanner {
|
||||||
@ -52,61 +59,3 @@ func parseScanners(inp []string) []scanner {
|
|||||||
}
|
}
|
||||||
return scanners
|
return scanners
|
||||||
}
|
}
|
||||||
|
|
||||||
type scanner struct {
|
|
||||||
number int
|
|
||||||
region map[h.Coordinate]bool
|
|
||||||
beacons []beacon
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewScanner(b []beacon) scanner {
|
|
||||||
return scanner{beacons: b}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewScannerFromInput(inp []string) (scanner, error) {
|
|
||||||
s := scanner{}
|
|
||||||
r := strings.NewReader(inp[0])
|
|
||||||
_, err := fmt.Fscanf(r, "--- scanner %d ---", &s.number)
|
|
||||||
if err != nil {
|
|
||||||
return s, errors.New("No Scanner ID")
|
|
||||||
}
|
|
||||||
for _, v := range inp[1:] {
|
|
||||||
r = strings.NewReader(v)
|
|
||||||
b := beacon{}
|
|
||||||
_, err := fmt.Fscanf(r, "%d,%d,%d", &b.x, &b.y, &b.z)
|
|
||||||
if err == nil {
|
|
||||||
s.beacons = append(s.beacons, b)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return s, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s scanner) allRotations() [][]beacon {
|
|
||||||
var beacons [][]beacon
|
|
||||||
for i := range s.beacons {
|
|
||||||
beacons = append(beacons, s.beacons[i].allRotations())
|
|
||||||
}
|
|
||||||
return beacons
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s scanner) String() string {
|
|
||||||
return fmt.Sprintf("-- Scanner %d (%d beacons)---", s.number, len(s.beacons))
|
|
||||||
}
|
|
||||||
|
|
||||||
type beacon struct {
|
|
||||||
x, y, z int
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b beacon) allRotations() []beacon {
|
|
||||||
return []beacon{
|
|
||||||
{b.x, b.y, b.z}, {b.x, -b.z, b.y}, {b.x, -b.y, -b.z}, {b.x, b.z, -b.y}, {-b.x, -b.y, b.z},
|
|
||||||
{-b.x, -b.z, -b.y}, {-b.x, b.y, -b.z}, {-b.x, b.z, b.y}, {-b.z, b.x, -b.y}, {b.y, b.x, -b.z},
|
|
||||||
{b.z, b.x, b.y}, {-b.y, b.x, b.z}, {b.z, -b.x, -b.y}, {b.y, -b.x, b.z}, {-b.z, -b.x, b.y},
|
|
||||||
{-b.y, -b.x, -b.z}, {-b.y, -b.z, b.x}, {b.z, -b.y, b.x}, {b.y, b.z, b.x}, {-b.z, b.y, b.x},
|
|
||||||
{b.z, b.y, -b.x}, {-b.y, b.z, -b.x}, {-b.z, -b.y, -b.x}, {b.y, -b.z, -b.x},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b beacon) String() string {
|
|
||||||
return fmt.Sprintf("{%d,%d,%d}", b.x, b.y, b.z)
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user