:work: Works on part 2 of day 10
This commit is contained in:
parent
0dadb796bc
commit
2661abe8db
@ -127,6 +127,92 @@ func CountAsteroidsFromPosition(field [][]int, posX, posY int) (sum int) {
|
||||
return
|
||||
}
|
||||
|
||||
func Vaporized(field [][]int, posX, posY int) {
|
||||
destroyed := make([]Position, 0)
|
||||
degree := 0.0
|
||||
// 0 bis 180 Grad positives steps X
|
||||
// 180 bis 0 Grad negatives steps X
|
||||
// 90 bis 270 Grad positives steps Y
|
||||
// 270 bi 90 Grad negatives steps Y
|
||||
|
||||
for true {
|
||||
|
||||
// Handle fixed Values
|
||||
if degree == 270 {
|
||||
currentX := posX
|
||||
for true {
|
||||
currentX--
|
||||
if currentX < 0 {
|
||||
break
|
||||
}
|
||||
|
||||
if field[posY][currentX] > 0 {
|
||||
field[posY][currentX] = -1
|
||||
destroyed = append(destroyed, Position{Y: posY, X: currentX})
|
||||
break
|
||||
}
|
||||
}
|
||||
degree++
|
||||
} else if degree == 90 {
|
||||
currentX := posX
|
||||
for true {
|
||||
currentX++
|
||||
if len(field[posY]) <= currentX {
|
||||
break
|
||||
}
|
||||
|
||||
if field[posY][currentX] > 0 {
|
||||
field[posY][currentX] = -1
|
||||
destroyed = append(destroyed, Position{Y: posY, X: currentX})
|
||||
break
|
||||
}
|
||||
}
|
||||
degree++
|
||||
} else if degree == 0 {
|
||||
currentY := posY
|
||||
for true {
|
||||
currentY--
|
||||
if currentY < 0 {
|
||||
break
|
||||
}
|
||||
|
||||
if field[currentY][posX] > 0 {
|
||||
field[currentY][posX] = -1
|
||||
destroyed = append(destroyed, Position{Y: currentY, X: posX})
|
||||
break
|
||||
}
|
||||
}
|
||||
degree++
|
||||
} else if degree == 180 {
|
||||
currentY := posY
|
||||
for true {
|
||||
currentY++
|
||||
if len(field) <= currentY {
|
||||
break
|
||||
}
|
||||
|
||||
if field[currentY][posX] > 0 {
|
||||
field[currentY][posX] = -1
|
||||
destroyed = append(destroyed, Position{Y: currentY, X: posX})
|
||||
break
|
||||
}
|
||||
}
|
||||
degree++
|
||||
}
|
||||
|
||||
if degree > 0 && degree < 90 {
|
||||
currentX := posX
|
||||
|
||||
for ; currentX < len(field[0]); currentX++ {
|
||||
for y := 0; y < len(field)-posY; y++ {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func Copy2DSlice(matrix [][]int) (duplicate [][]int) {
|
||||
duplicate = make([][]int, len(matrix))
|
||||
for i := range matrix {
|
||||
|
Loading…
Reference in New Issue
Block a user