mirror of
https://github.com/Threnklyn/advent-of-code-go.git
synced 2026-06-07 20:53:30 +02:00
a little bit of cleanup, had rotations creating a bit off originally
This commit is contained in:
+10
-27
@@ -52,13 +52,11 @@ func part1(input string) (part1, part2 int) {
|
|||||||
undetermined := scanners[1:]
|
undetermined := scanners[1:]
|
||||||
// iterate while it has a non zero length
|
// iterate while it has a non zero length
|
||||||
for len(undetermined) > 0 {
|
for len(undetermined) > 0 {
|
||||||
fmt.Println("undetermined:", len(undetermined))
|
fmt.Printf("progress: %d/%d\n", len(settled), len(scanners))
|
||||||
|
|
||||||
for i, undet := range undetermined {
|
for i, undet := range undetermined {
|
||||||
maybeUpdated, ok := findAbsoluteCoordsForScanner(undet, settled)
|
maybeUpdated, ok := findAbsoluteCoordsForScanner(undet, settled)
|
||||||
if ok {
|
if ok {
|
||||||
// fmt.Printf("found abs for scanner %d\n", maybeUpdated.number)
|
|
||||||
// fmt.Printf("updated to: %+v\n", maybeUpdated)
|
|
||||||
settled = append(settled, maybeUpdated)
|
settled = append(settled, maybeUpdated)
|
||||||
// remove the determined scanner from undetermined list
|
// remove the determined scanner from undetermined list
|
||||||
copy(undetermined[i:], undetermined[i+1:])
|
copy(undetermined[i:], undetermined[i+1:])
|
||||||
@@ -72,7 +70,6 @@ func part1(input string) (part1, part2 int) {
|
|||||||
|
|
||||||
allBeacons := map[[3]int]bool{}
|
allBeacons := map[[3]int]bool{}
|
||||||
for _, s := range settled {
|
for _, s := range settled {
|
||||||
// fmt.Printf("\n%+v\n", s)
|
|
||||||
for c := range s.absoluteCoordsMap {
|
for c := range s.absoluteCoordsMap {
|
||||||
allBeacons[c] = true
|
allBeacons[c] = true
|
||||||
}
|
}
|
||||||
@@ -93,10 +90,6 @@ func part1(input string) (part1, part2 int) {
|
|||||||
return len(allBeacons), furthest
|
return len(allBeacons), furthest
|
||||||
}
|
}
|
||||||
|
|
||||||
func part2(input string) int {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
type scanner struct {
|
type scanner struct {
|
||||||
number int
|
number int
|
||||||
x, y, z int
|
x, y, z int
|
||||||
@@ -120,24 +113,19 @@ func (s *scanner) fillAbsoluteCoordsMap() {
|
|||||||
func (s *scanner) fillRotations() {
|
func (s *scanner) fillRotations() {
|
||||||
// facing negative x
|
// facing negative x
|
||||||
posX := s.relativeCoords
|
posX := s.relativeCoords
|
||||||
var negX, posY, negY, posZ, negZ [][3]int
|
var dir2, dir3, dir4, dir5, dir6 [][3]int
|
||||||
for _, c := range posX {
|
for _, c := range posX {
|
||||||
x, y, z := c[0], c[1], c[2]
|
x, y, z := c[0], c[1], c[2]
|
||||||
// negX = append(negX, [3]int{-x, -y, z})
|
dir2 = append(dir2, [3]int{x, -y, -z})
|
||||||
// posY = append(posY, [3]int{y, -x, -z})
|
dir3 = append(dir3, [3]int{x, -z, y})
|
||||||
// negY = append(negY, [3]int{-y, x, z})
|
dir4 = append(dir4, [3]int{-y, -z, x})
|
||||||
// posZ = append(posZ, [3]int{z, -x, -y})
|
dir5 = append(dir5, [3]int{-x, -z, -y})
|
||||||
// negZ = append(negZ, [3]int{-z, -x, y})
|
dir6 = append(dir6, [3]int{y, -z, -x})
|
||||||
negX = append(negX, [3]int{x, -y, -z})
|
|
||||||
posY = append(posY, [3]int{x, -z, y})
|
|
||||||
negY = append(negY, [3]int{-y, -z, x})
|
|
||||||
posZ = append(posZ, [3]int{-x, -z, -y})
|
|
||||||
negZ = append(negZ, [3]int{y, -z, -x})
|
|
||||||
}
|
}
|
||||||
sixRotations := [][][3]int{
|
sixRotations := [][][3]int{
|
||||||
posX, negX,
|
posX, dir2,
|
||||||
posY, negY,
|
dir3, dir4,
|
||||||
posZ, negZ,
|
dir5, dir6,
|
||||||
}
|
}
|
||||||
|
|
||||||
// apply 4 rotations around the axis that the scanner is "staring down"
|
// apply 4 rotations around the axis that the scanner is "staring down"
|
||||||
@@ -146,9 +134,6 @@ func (s *scanner) fillRotations() {
|
|||||||
var r2, r3, r4 [][3]int // r1 is rotation itself
|
var r2, r3, r4 [][3]int // r1 is rotation itself
|
||||||
for _, c := range rotation {
|
for _, c := range rotation {
|
||||||
x, y, z := c[0], c[1], c[2]
|
x, y, z := c[0], c[1], c[2]
|
||||||
// r2 = append(r2, [3]int{x, z, -y})
|
|
||||||
// r3 = append(r3, [3]int{x, -y, -z})
|
|
||||||
// r4 = append(r4, [3]int{x, -z, y})
|
|
||||||
r2 = append(r2, [3]int{-y, x, z})
|
r2 = append(r2, [3]int{-y, x, z})
|
||||||
r3 = append(r3, [3]int{-x, -y, z})
|
r3 = append(r3, [3]int{-x, -y, z})
|
||||||
r4 = append(r4, [3]int{y, -x, z})
|
r4 = append(r4, [3]int{y, -x, z})
|
||||||
@@ -169,7 +154,6 @@ func findAbsoluteCoordsForScanner(undet scanner, settled []scanner) (maybeUpdate
|
|||||||
// assume the known and unknown beacon are the same, calculate the absolute coords of the unknown's scanner coords
|
// assume the known and unknown beacon are the same, calculate the absolute coords of the unknown's scanner coords
|
||||||
// convert all of unknown list to their absolute coords, check against known list
|
// convert all of unknown list to their absolute coords, check against known list
|
||||||
unsettledAbsoluteCoords := makeAbsoluteCoordsList(absCoord, relativeCoord, rotatedCoords)
|
unsettledAbsoluteCoords := makeAbsoluteCoordsList(absCoord, relativeCoord, rotatedCoords)
|
||||||
// fmt.Println("\tgenerated abs coords", unsettledAbsoluteCoords)
|
|
||||||
|
|
||||||
var matchingCount int
|
var matchingCount int
|
||||||
// var matched [][3]int // !
|
// var matched [][3]int // !
|
||||||
@@ -182,7 +166,6 @@ func findAbsoluteCoordsForScanner(undet scanner, settled []scanner) (maybeUpdate
|
|||||||
|
|
||||||
// if true return a true or something, modify the scanner param pointer
|
// if true return a true or something, modify the scanner param pointer
|
||||||
if matchingCount >= 12 {
|
if matchingCount >= 12 {
|
||||||
// fmt.Println("matched coords", set.number, "&", undet.number, matched) // !
|
|
||||||
undet.relativeCoords = rotatedCoords
|
undet.relativeCoords = rotatedCoords
|
||||||
undet.absoluteCoords = unsettledAbsoluteCoords
|
undet.absoluteCoords = unsettledAbsoluteCoords
|
||||||
undet.fillAbsoluteCoordsMap()
|
undet.fillAbsoluteCoordsMap()
|
||||||
|
|||||||
@@ -192,32 +192,6 @@ func Test_part1(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_part2(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
input string
|
|
||||||
want int
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "example",
|
|
||||||
input: example,
|
|
||||||
want: 0,
|
|
||||||
},
|
|
||||||
// {
|
|
||||||
// name: "actual",
|
|
||||||
// input: input,
|
|
||||||
// want: 0,
|
|
||||||
// },
|
|
||||||
}
|
|
||||||
for _, tt := range tests {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
if got := part2(tt.input); got != tt.want {
|
|
||||||
t.Errorf("part2() = %v, want %v", got, tt.want)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var allTheSameScanner = `--- scanner 0 ---
|
var allTheSameScanner = `--- scanner 0 ---
|
||||||
-1,-1,1
|
-1,-1,1
|
||||||
-2,-2,2
|
-2,-2,2
|
||||||
|
|||||||
Reference in New Issue
Block a user