Day15
This commit is contained in:
parent
2b17f3554a
commit
8da77203f0
@ -3,30 +3,60 @@ package main
|
|||||||
import (
|
import (
|
||||||
"AOC2022/helper"
|
"AOC2022/helper"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
//args := os.Args[1:]
|
args := os.Args[1:]
|
||||||
lines := helper.ReadTextFile("day15/input")
|
lines := helper.ReadTextFile(args[0])
|
||||||
points := getPoints(lines)
|
points := getPoints(lines)
|
||||||
//scannedXPoints := make(map[int]bool)
|
//scannedXPoints := make(map[int]bool)
|
||||||
scannedPoints := getScannedPointsForTagetY(points, [2]int{0, 4000000}, [2]int{0, 4000000})
|
scannedPoints := getScannedPointsForTagetY(points, [2]int{2000000, 2000000}, [2]int{-100000000, 100000000})
|
||||||
//fmt.Println(scannedPoints)
|
fmt.Println(len(scannedPoints) - 1)
|
||||||
fmt.Println(len(scannedPoints))
|
part2(points)
|
||||||
for i := 0; i <= 4000000; i++ {
|
}
|
||||||
for j := 0; j <= 20; j++ {
|
|
||||||
if !scannedPoints[[2]int{i, j}] {
|
// Fichtes Solution
|
||||||
fmt.Println([2]int{i, j})
|
func part2(points [][2][2]int) {
|
||||||
|
scannerWithDistances := [][3]int{}
|
||||||
|
for _, scannedPoint := range points {
|
||||||
|
distance := helper.ManHattanDistance(scannedPoint[0], scannedPoint[1])
|
||||||
|
scannerWithDistances = append(scannerWithDistances, [3]int{scannedPoint[0][0], scannedPoint[0][1], distance})
|
||||||
|
}
|
||||||
|
startPoint := [2]int{0, 0}
|
||||||
|
finish := false
|
||||||
|
for !finish {
|
||||||
|
scanner := checkIfPointIsInScannerReach(startPoint, scannerWithDistances)
|
||||||
|
if scanner[2] == -1 {
|
||||||
|
finish = true
|
||||||
|
} else {
|
||||||
|
distanceToTargetY := helper.Abs(scanner[1] - startPoint[1])
|
||||||
|
widthOnTargetY := helper.Abs(distanceToTargetY - scanner[2])
|
||||||
|
newXValue := scanner[0] + widthOnTargetY + 1
|
||||||
|
if newXValue > 4000000 {
|
||||||
|
startPoint = [2]int{0, startPoint[1] + 1}
|
||||||
|
} else {
|
||||||
|
startPoint[0] = newXValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fmt.Println(startPoint[0]*4000000 + startPoint[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkIfPointIsInScannerReach(point [2]int, scanners [][3]int) [3]int {
|
||||||
|
for _, scannerWithDistance := range scanners {
|
||||||
|
if helper.ManHattanDistance(point, [2]int{scannerWithDistance[0], scannerWithDistance[1]}) <= scannerWithDistance[2] {
|
||||||
|
return scannerWithDistance
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return [3]int{0, 0, -1}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getScannedPointsForTagetY(points [][2][2]int, targetyRange [2]int, targetxRange [2]int) map[[2]int]bool {
|
func getScannedPointsForTagetY(points [][2][2]int, targetyRange [2]int, targetxRange [2]int) map[[2]int]bool {
|
||||||
scannedYPoints := make(map[[2]int]bool)
|
scannedYPoints := make(map[[2]int]bool)
|
||||||
for rotation, pointPair := range points {
|
for _, pointPair := range points {
|
||||||
sensor := pointPair[0]
|
sensor := pointPair[0]
|
||||||
beacon := pointPair[1]
|
beacon := pointPair[1]
|
||||||
distanceToSensor := helper.ManHattanDistance(sensor, beacon)
|
distanceToSensor := helper.ManHattanDistance(sensor, beacon)
|
||||||
@ -58,7 +88,6 @@ func getScannedPointsForTagetY(points [][2][2]int, targetyRange [2]int, targetxR
|
|||||||
i--
|
i--
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Println(rotation)
|
|
||||||
}
|
}
|
||||||
return scannedYPoints
|
return scannedYPoints
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user