This commit is contained in:
Karl Spickermann 2022-12-15 01:02:04 +01:00
parent 8e5dfcccd8
commit e2f5bc8e52
4 changed files with 318 additions and 0 deletions

156
day14/day14.go Normal file

@ -0,0 +1,156 @@
package main
import (
"AOC2022/helper"
"fmt"
"os"
"strconv"
"strings"
)
func main() {
args := os.Args[1:]
lines := helper.ReadTextFile(args[0])
cave := generateCavePart(lines, 2)
run := 0
steps := 0
for run == 0 {
run = step(&cave)
steps++
}
//print(cave)
fmt.Println(steps - 1)
cave = generateCavePart(lines, 0)
run = 0
steps = 0
for run == 0 {
run = step(&cave)
steps++
}
fmt.Println(steps)
}
func step(cave *[][]rune) int {
sandDestination := getSandDestination(cave)
if sandDestination == [2]int{0, 500} {
helper.SetValueOf2DMap(sandDestination, 'o', cave)
return -1
}
return helper.SetValueOf2DMap(sandDestination, 'o', cave)
}
func getSandDestination(cave *[][]rune) (destination [2]int) {
startPoint := [2]int{0, 500}
if helper.RemoveError(helper.GetValueOf2DMap(startPoint, cave)) != '.' {
return startPoint
}
destination = [2]int{-1, -1}
for destination == [2]int{-1, -1} {
possibleNextPoint := startPoint
possibleNextPoint[0]++
getValue, err := helper.GetValueOf2DMap(possibleNextPoint, cave)
if err != nil {
return possibleNextPoint
}
if getValue != '.' {
diagonalMovePoint := diagonalMove(cave, possibleNextPoint)
if diagonalMovePoint == possibleNextPoint {
destination = startPoint
} else {
startPoint = diagonalMovePoint
}
} else {
startPoint = possibleNextPoint
}
}
return
}
func diagonalMove(cave *[][]rune, startPoint [2]int) [2]int {
potenTialPoints := [2][2]int{}
tempPoint := startPoint
tempPoint[1]--
potenTialPoints[0] = tempPoint
tempPoint[1] += 2
potenTialPoints[1] = tempPoint
for _, point := range potenTialPoints {
if helper.RemoveError(helper.GetValueOf2DMap(point, cave)) == '.' {
return point
}
}
return startPoint
}
func generateCavePart(lines []string, additionalSpace int) [][]rune {
lowestPoint := 0
cave := [200][]rune{}
for i := 0; i < len(cave); i++ {
cave[i] = []rune(strings.Repeat(".", 1000))
}
for _, line := range lines {
points := getPoints(line)
for _, point := range points {
if point[1] > lowestPoint {
lowestPoint = point[1]
}
}
drawLine(&cave, points)
}
lowestPoint += additionalSpace
if additionalSpace > 0 {
drawLine(&cave, [][2]int{{0, lowestPoint}, {999, lowestPoint}})
}
//print(cave[:lowestPoint+1])
return cave[:lowestPoint+1]
}
//x represents distance to the right and y represents distance down.
func drawLine(cave *[200][]rune, points [][2]int) {
for i := 0; i < len(points)-1; i++ {
point := points[i]
nextPoint := points[i+1]
if point[0] == nextPoint[0] {
direction := 1
if point[1]-nextPoint[1] > 0 {
direction = -1
}
for j := point[1] - direction; j != nextPoint[1]; {
j += direction
cave[j][point[0]] = '#'
}
} else {
direction := 1
if point[0]-nextPoint[0] > 0 {
direction = -1
}
for j := point[0] - direction; j != nextPoint[0]; {
j += direction
cave[point[1]][j] = '#'
}
}
}
}
func getPoints(line string) (points [][2]int) {
for _, pointsString := range strings.Split(line, " -> ") {
point := [2]int{}
for i, pointString := range strings.Split(pointsString, ",") {
point[i] = helper.RemoveError(strconv.Atoi(pointString))
}
point[0] = point[0]
points = append(points, point)
}
return
}
func print(cave [][]rune) {
fmt.Println()
fmt.Println(strings.Repeat(" ", 25) + "V" + strings.Repeat(" ", 24))
for _, line := range cave {
fmt.Println(string(line))
}
}

138
day14/input Normal file

@ -0,0 +1,138 @@
486,40 -> 486,44 -> 482,44 -> 482,49 -> 499,49 -> 499,44 -> 491,44 -> 491,40
487,60 -> 487,61 -> 503,61 -> 503,60
495,21 -> 501,21 -> 501,20
501,165 -> 501,155 -> 501,165 -> 503,165 -> 503,157 -> 503,165 -> 505,165 -> 505,160 -> 505,165 -> 507,165 -> 507,156 -> 507,165 -> 509,165 -> 509,163 -> 509,165 -> 511,165 -> 511,163 -> 511,165 -> 513,165 -> 513,158 -> 513,165 -> 515,165 -> 515,160 -> 515,165 -> 517,165 -> 517,160 -> 517,165 -> 519,165 -> 519,156 -> 519,165
499,123 -> 503,123
501,165 -> 501,155 -> 501,165 -> 503,165 -> 503,157 -> 503,165 -> 505,165 -> 505,160 -> 505,165 -> 507,165 -> 507,156 -> 507,165 -> 509,165 -> 509,163 -> 509,165 -> 511,165 -> 511,163 -> 511,165 -> 513,165 -> 513,158 -> 513,165 -> 515,165 -> 515,160 -> 515,165 -> 517,165 -> 517,160 -> 517,165 -> 519,165 -> 519,156 -> 519,165
514,125 -> 518,125
485,92 -> 485,89 -> 485,92 -> 487,92 -> 487,84 -> 487,92 -> 489,92 -> 489,89 -> 489,92 -> 491,92 -> 491,88 -> 491,92 -> 493,92 -> 493,85 -> 493,92 -> 495,92 -> 495,82 -> 495,92 -> 497,92 -> 497,91 -> 497,92
508,121 -> 512,121
498,58 -> 503,58
487,60 -> 487,61 -> 503,61 -> 503,60
508,125 -> 512,125
486,40 -> 486,44 -> 482,44 -> 482,49 -> 499,49 -> 499,44 -> 491,44 -> 491,40
486,79 -> 491,79
494,55 -> 499,55
485,92 -> 485,89 -> 485,92 -> 487,92 -> 487,84 -> 487,92 -> 489,92 -> 489,89 -> 489,92 -> 491,92 -> 491,88 -> 491,92 -> 493,92 -> 493,85 -> 493,92 -> 495,92 -> 495,82 -> 495,92 -> 497,92 -> 497,91 -> 497,92
485,92 -> 485,89 -> 485,92 -> 487,92 -> 487,84 -> 487,92 -> 489,92 -> 489,89 -> 489,92 -> 491,92 -> 491,88 -> 491,92 -> 493,92 -> 493,85 -> 493,92 -> 495,92 -> 495,82 -> 495,92 -> 497,92 -> 497,91 -> 497,92
501,165 -> 501,155 -> 501,165 -> 503,165 -> 503,157 -> 503,165 -> 505,165 -> 505,160 -> 505,165 -> 507,165 -> 507,156 -> 507,165 -> 509,165 -> 509,163 -> 509,165 -> 511,165 -> 511,163 -> 511,165 -> 513,165 -> 513,158 -> 513,165 -> 515,165 -> 515,160 -> 515,165 -> 517,165 -> 517,160 -> 517,165 -> 519,165 -> 519,156 -> 519,165
485,92 -> 485,89 -> 485,92 -> 487,92 -> 487,84 -> 487,92 -> 489,92 -> 489,89 -> 489,92 -> 491,92 -> 491,88 -> 491,92 -> 493,92 -> 493,85 -> 493,92 -> 495,92 -> 495,82 -> 495,92 -> 497,92 -> 497,91 -> 497,92
495,105 -> 495,99 -> 495,105 -> 497,105 -> 497,97 -> 497,105 -> 499,105 -> 499,103 -> 499,105 -> 501,105 -> 501,102 -> 501,105
501,165 -> 501,155 -> 501,165 -> 503,165 -> 503,157 -> 503,165 -> 505,165 -> 505,160 -> 505,165 -> 507,165 -> 507,156 -> 507,165 -> 509,165 -> 509,163 -> 509,165 -> 511,165 -> 511,163 -> 511,165 -> 513,165 -> 513,158 -> 513,165 -> 515,165 -> 515,160 -> 515,165 -> 517,165 -> 517,160 -> 517,165 -> 519,165 -> 519,156 -> 519,165
491,58 -> 496,58
502,64 -> 506,64
500,108 -> 500,112 -> 494,112 -> 494,116 -> 506,116 -> 506,112 -> 505,112 -> 505,108
485,92 -> 485,89 -> 485,92 -> 487,92 -> 487,84 -> 487,92 -> 489,92 -> 489,89 -> 489,92 -> 491,92 -> 491,88 -> 491,92 -> 493,92 -> 493,85 -> 493,92 -> 495,92 -> 495,82 -> 495,92 -> 497,92 -> 497,91 -> 497,92
482,37 -> 482,27 -> 482,37 -> 484,37 -> 484,28 -> 484,37 -> 486,37 -> 486,27 -> 486,37 -> 488,37 -> 488,27 -> 488,37
485,92 -> 485,89 -> 485,92 -> 487,92 -> 487,84 -> 487,92 -> 489,92 -> 489,89 -> 489,92 -> 491,92 -> 491,88 -> 491,92 -> 493,92 -> 493,85 -> 493,92 -> 495,92 -> 495,82 -> 495,92 -> 497,92 -> 497,91 -> 497,92
501,165 -> 501,155 -> 501,165 -> 503,165 -> 503,157 -> 503,165 -> 505,165 -> 505,160 -> 505,165 -> 507,165 -> 507,156 -> 507,165 -> 509,165 -> 509,163 -> 509,165 -> 511,165 -> 511,163 -> 511,165 -> 513,165 -> 513,158 -> 513,165 -> 515,165 -> 515,160 -> 515,165 -> 517,165 -> 517,160 -> 517,165 -> 519,165 -> 519,156 -> 519,165
495,105 -> 495,99 -> 495,105 -> 497,105 -> 497,97 -> 497,105 -> 499,105 -> 499,103 -> 499,105 -> 501,105 -> 501,102 -> 501,105
492,73 -> 497,73
511,123 -> 515,123
495,21 -> 501,21 -> 501,20
496,76 -> 501,76
485,92 -> 485,89 -> 485,92 -> 487,92 -> 487,84 -> 487,92 -> 489,92 -> 489,89 -> 489,92 -> 491,92 -> 491,88 -> 491,92 -> 493,92 -> 493,85 -> 493,92 -> 495,92 -> 495,82 -> 495,92 -> 497,92 -> 497,91 -> 497,92
485,92 -> 485,89 -> 485,92 -> 487,92 -> 487,84 -> 487,92 -> 489,92 -> 489,89 -> 489,92 -> 491,92 -> 491,88 -> 491,92 -> 493,92 -> 493,85 -> 493,92 -> 495,92 -> 495,82 -> 495,92 -> 497,92 -> 497,91 -> 497,92
501,165 -> 501,155 -> 501,165 -> 503,165 -> 503,157 -> 503,165 -> 505,165 -> 505,160 -> 505,165 -> 507,165 -> 507,156 -> 507,165 -> 509,165 -> 509,163 -> 509,165 -> 511,165 -> 511,163 -> 511,165 -> 513,165 -> 513,158 -> 513,165 -> 515,165 -> 515,160 -> 515,165 -> 517,165 -> 517,160 -> 517,165 -> 519,165 -> 519,156 -> 519,165
485,92 -> 485,89 -> 485,92 -> 487,92 -> 487,84 -> 487,92 -> 489,92 -> 489,89 -> 489,92 -> 491,92 -> 491,88 -> 491,92 -> 493,92 -> 493,85 -> 493,92 -> 495,92 -> 495,82 -> 495,92 -> 497,92 -> 497,91 -> 497,92
500,79 -> 505,79
495,105 -> 495,99 -> 495,105 -> 497,105 -> 497,97 -> 497,105 -> 499,105 -> 499,103 -> 499,105 -> 501,105 -> 501,102 -> 501,105
500,108 -> 500,112 -> 494,112 -> 494,116 -> 506,116 -> 506,112 -> 505,112 -> 505,108
495,105 -> 495,99 -> 495,105 -> 497,105 -> 497,97 -> 497,105 -> 499,105 -> 499,103 -> 499,105 -> 501,105 -> 501,102 -> 501,105
501,165 -> 501,155 -> 501,165 -> 503,165 -> 503,157 -> 503,165 -> 505,165 -> 505,160 -> 505,165 -> 507,165 -> 507,156 -> 507,165 -> 509,165 -> 509,163 -> 509,165 -> 511,165 -> 511,163 -> 511,165 -> 513,165 -> 513,158 -> 513,165 -> 515,165 -> 515,160 -> 515,165 -> 517,165 -> 517,160 -> 517,165 -> 519,165 -> 519,156 -> 519,165
501,165 -> 501,155 -> 501,165 -> 503,165 -> 503,157 -> 503,165 -> 505,165 -> 505,160 -> 505,165 -> 507,165 -> 507,156 -> 507,165 -> 509,165 -> 509,163 -> 509,165 -> 511,165 -> 511,163 -> 511,165 -> 513,165 -> 513,158 -> 513,165 -> 515,165 -> 515,160 -> 515,165 -> 517,165 -> 517,160 -> 517,165 -> 519,165 -> 519,156 -> 519,165
485,92 -> 485,89 -> 485,92 -> 487,92 -> 487,84 -> 487,92 -> 489,92 -> 489,89 -> 489,92 -> 491,92 -> 491,88 -> 491,92 -> 493,92 -> 493,85 -> 493,92 -> 495,92 -> 495,82 -> 495,92 -> 497,92 -> 497,91 -> 497,92
486,40 -> 486,44 -> 482,44 -> 482,49 -> 499,49 -> 499,44 -> 491,44 -> 491,40
513,141 -> 513,145 -> 512,145 -> 512,152 -> 523,152 -> 523,145 -> 518,145 -> 518,141
501,165 -> 501,155 -> 501,165 -> 503,165 -> 503,157 -> 503,165 -> 505,165 -> 505,160 -> 505,165 -> 507,165 -> 507,156 -> 507,165 -> 509,165 -> 509,163 -> 509,165 -> 511,165 -> 511,163 -> 511,165 -> 513,165 -> 513,158 -> 513,165 -> 515,165 -> 515,160 -> 515,165 -> 517,165 -> 517,160 -> 517,165 -> 519,165 -> 519,156 -> 519,165
505,119 -> 509,119
496,70 -> 500,70
482,37 -> 482,27 -> 482,37 -> 484,37 -> 484,28 -> 484,37 -> 486,37 -> 486,27 -> 486,37 -> 488,37 -> 488,27 -> 488,37
505,123 -> 509,123
501,165 -> 501,155 -> 501,165 -> 503,165 -> 503,157 -> 503,165 -> 505,165 -> 505,160 -> 505,165 -> 507,165 -> 507,156 -> 507,165 -> 509,165 -> 509,163 -> 509,165 -> 511,165 -> 511,163 -> 511,165 -> 513,165 -> 513,158 -> 513,165 -> 515,165 -> 515,160 -> 515,165 -> 517,165 -> 517,160 -> 517,165 -> 519,165 -> 519,156 -> 519,165
496,125 -> 500,125
501,165 -> 501,155 -> 501,165 -> 503,165 -> 503,157 -> 503,165 -> 505,165 -> 505,160 -> 505,165 -> 507,165 -> 507,156 -> 507,165 -> 509,165 -> 509,163 -> 509,165 -> 511,165 -> 511,163 -> 511,165 -> 513,165 -> 513,158 -> 513,165 -> 515,165 -> 515,160 -> 515,165 -> 517,165 -> 517,160 -> 517,165 -> 519,165 -> 519,156 -> 519,165
502,121 -> 506,121
501,165 -> 501,155 -> 501,165 -> 503,165 -> 503,157 -> 503,165 -> 505,165 -> 505,160 -> 505,165 -> 507,165 -> 507,156 -> 507,165 -> 509,165 -> 509,163 -> 509,165 -> 511,165 -> 511,163 -> 511,165 -> 513,165 -> 513,158 -> 513,165 -> 515,165 -> 515,160 -> 515,165 -> 517,165 -> 517,160 -> 517,165 -> 519,165 -> 519,156 -> 519,165
505,67 -> 509,67
485,92 -> 485,89 -> 485,92 -> 487,92 -> 487,84 -> 487,92 -> 489,92 -> 489,89 -> 489,92 -> 491,92 -> 491,88 -> 491,92 -> 493,92 -> 493,85 -> 493,92 -> 495,92 -> 495,82 -> 495,92 -> 497,92 -> 497,91 -> 497,92
501,165 -> 501,155 -> 501,165 -> 503,165 -> 503,157 -> 503,165 -> 505,165 -> 505,160 -> 505,165 -> 507,165 -> 507,156 -> 507,165 -> 509,165 -> 509,163 -> 509,165 -> 511,165 -> 511,163 -> 511,165 -> 513,165 -> 513,158 -> 513,165 -> 515,165 -> 515,160 -> 515,165 -> 517,165 -> 517,160 -> 517,165 -> 519,165 -> 519,156 -> 519,165
482,37 -> 482,27 -> 482,37 -> 484,37 -> 484,28 -> 484,37 -> 486,37 -> 486,27 -> 486,37 -> 488,37 -> 488,27 -> 488,37
518,128 -> 518,130 -> 516,130 -> 516,138 -> 525,138 -> 525,130 -> 522,130 -> 522,128
518,128 -> 518,130 -> 516,130 -> 516,138 -> 525,138 -> 525,130 -> 522,130 -> 522,128
482,37 -> 482,27 -> 482,37 -> 484,37 -> 484,28 -> 484,37 -> 486,37 -> 486,27 -> 486,37 -> 488,37 -> 488,27 -> 488,37
485,92 -> 485,89 -> 485,92 -> 487,92 -> 487,84 -> 487,92 -> 489,92 -> 489,89 -> 489,92 -> 491,92 -> 491,88 -> 491,92 -> 493,92 -> 493,85 -> 493,92 -> 495,92 -> 495,82 -> 495,92 -> 497,92 -> 497,91 -> 497,92
500,108 -> 500,112 -> 494,112 -> 494,116 -> 506,116 -> 506,112 -> 505,112 -> 505,108
501,165 -> 501,155 -> 501,165 -> 503,165 -> 503,157 -> 503,165 -> 505,165 -> 505,160 -> 505,165 -> 507,165 -> 507,156 -> 507,165 -> 509,165 -> 509,163 -> 509,165 -> 511,165 -> 511,163 -> 511,165 -> 513,165 -> 513,158 -> 513,165 -> 515,165 -> 515,160 -> 515,165 -> 517,165 -> 517,160 -> 517,165 -> 519,165 -> 519,156 -> 519,165
489,76 -> 494,76
485,92 -> 485,89 -> 485,92 -> 487,92 -> 487,84 -> 487,92 -> 489,92 -> 489,89 -> 489,92 -> 491,92 -> 491,88 -> 491,92 -> 493,92 -> 493,85 -> 493,92 -> 495,92 -> 495,82 -> 495,92 -> 497,92 -> 497,91 -> 497,92
485,92 -> 485,89 -> 485,92 -> 487,92 -> 487,84 -> 487,92 -> 489,92 -> 489,89 -> 489,92 -> 491,92 -> 491,88 -> 491,92 -> 493,92 -> 493,85 -> 493,92 -> 495,92 -> 495,82 -> 495,92 -> 497,92 -> 497,91 -> 497,92
501,165 -> 501,155 -> 501,165 -> 503,165 -> 503,157 -> 503,165 -> 505,165 -> 505,160 -> 505,165 -> 507,165 -> 507,156 -> 507,165 -> 509,165 -> 509,163 -> 509,165 -> 511,165 -> 511,163 -> 511,165 -> 513,165 -> 513,158 -> 513,165 -> 515,165 -> 515,160 -> 515,165 -> 517,165 -> 517,160 -> 517,165 -> 519,165 -> 519,156 -> 519,165
498,15 -> 498,16 -> 508,16 -> 508,15
500,108 -> 500,112 -> 494,112 -> 494,116 -> 506,116 -> 506,112 -> 505,112 -> 505,108
482,37 -> 482,27 -> 482,37 -> 484,37 -> 484,28 -> 484,37 -> 486,37 -> 486,27 -> 486,37 -> 488,37 -> 488,27 -> 488,37
486,40 -> 486,44 -> 482,44 -> 482,49 -> 499,49 -> 499,44 -> 491,44 -> 491,40
502,70 -> 506,70
501,165 -> 501,155 -> 501,165 -> 503,165 -> 503,157 -> 503,165 -> 505,165 -> 505,160 -> 505,165 -> 507,165 -> 507,156 -> 507,165 -> 509,165 -> 509,163 -> 509,165 -> 511,165 -> 511,163 -> 511,165 -> 513,165 -> 513,158 -> 513,165 -> 515,165 -> 515,160 -> 515,165 -> 517,165 -> 517,160 -> 517,165 -> 519,165 -> 519,156 -> 519,165
513,141 -> 513,145 -> 512,145 -> 512,152 -> 523,152 -> 523,145 -> 518,145 -> 518,141
501,165 -> 501,155 -> 501,165 -> 503,165 -> 503,157 -> 503,165 -> 505,165 -> 505,160 -> 505,165 -> 507,165 -> 507,156 -> 507,165 -> 509,165 -> 509,163 -> 509,165 -> 511,165 -> 511,163 -> 511,165 -> 513,165 -> 513,158 -> 513,165 -> 515,165 -> 515,160 -> 515,165 -> 517,165 -> 517,160 -> 517,165 -> 519,165 -> 519,156 -> 519,165
501,165 -> 501,155 -> 501,165 -> 503,165 -> 503,157 -> 503,165 -> 505,165 -> 505,160 -> 505,165 -> 507,165 -> 507,156 -> 507,165 -> 509,165 -> 509,163 -> 509,165 -> 511,165 -> 511,163 -> 511,165 -> 513,165 -> 513,158 -> 513,165 -> 515,165 -> 515,160 -> 515,165 -> 517,165 -> 517,160 -> 517,165 -> 519,165 -> 519,156 -> 519,165
487,60 -> 487,61 -> 503,61 -> 503,60
501,165 -> 501,155 -> 501,165 -> 503,165 -> 503,157 -> 503,165 -> 505,165 -> 505,160 -> 505,165 -> 507,165 -> 507,156 -> 507,165 -> 509,165 -> 509,163 -> 509,165 -> 511,165 -> 511,163 -> 511,165 -> 513,165 -> 513,158 -> 513,165 -> 515,165 -> 515,160 -> 515,165 -> 517,165 -> 517,160 -> 517,165 -> 519,165 -> 519,156 -> 519,165
501,165 -> 501,155 -> 501,165 -> 503,165 -> 503,157 -> 503,165 -> 505,165 -> 505,160 -> 505,165 -> 507,165 -> 507,156 -> 507,165 -> 509,165 -> 509,163 -> 509,165 -> 511,165 -> 511,163 -> 511,165 -> 513,165 -> 513,158 -> 513,165 -> 515,165 -> 515,160 -> 515,165 -> 517,165 -> 517,160 -> 517,165 -> 519,165 -> 519,156 -> 519,165
518,128 -> 518,130 -> 516,130 -> 516,138 -> 525,138 -> 525,130 -> 522,130 -> 522,128
513,141 -> 513,145 -> 512,145 -> 512,152 -> 523,152 -> 523,145 -> 518,145 -> 518,141
501,165 -> 501,155 -> 501,165 -> 503,165 -> 503,157 -> 503,165 -> 505,165 -> 505,160 -> 505,165 -> 507,165 -> 507,156 -> 507,165 -> 509,165 -> 509,163 -> 509,165 -> 511,165 -> 511,163 -> 511,165 -> 513,165 -> 513,158 -> 513,165 -> 515,165 -> 515,160 -> 515,165 -> 517,165 -> 517,160 -> 517,165 -> 519,165 -> 519,156 -> 519,165
482,37 -> 482,27 -> 482,37 -> 484,37 -> 484,28 -> 484,37 -> 486,37 -> 486,27 -> 486,37 -> 488,37 -> 488,27 -> 488,37
502,125 -> 506,125
495,105 -> 495,99 -> 495,105 -> 497,105 -> 497,97 -> 497,105 -> 499,105 -> 499,103 -> 499,105 -> 501,105 -> 501,102 -> 501,105
495,105 -> 495,99 -> 495,105 -> 497,105 -> 497,97 -> 497,105 -> 499,105 -> 499,103 -> 499,105 -> 501,105 -> 501,102 -> 501,105
513,141 -> 513,145 -> 512,145 -> 512,152 -> 523,152 -> 523,145 -> 518,145 -> 518,141
493,79 -> 498,79
485,92 -> 485,89 -> 485,92 -> 487,92 -> 487,84 -> 487,92 -> 489,92 -> 489,89 -> 489,92 -> 491,92 -> 491,88 -> 491,92 -> 493,92 -> 493,85 -> 493,92 -> 495,92 -> 495,82 -> 495,92 -> 497,92 -> 497,91 -> 497,92
487,23 -> 487,24 -> 496,24 -> 496,23
513,141 -> 513,145 -> 512,145 -> 512,152 -> 523,152 -> 523,145 -> 518,145 -> 518,141
487,23 -> 487,24 -> 496,24 -> 496,23
501,165 -> 501,155 -> 501,165 -> 503,165 -> 503,157 -> 503,165 -> 505,165 -> 505,160 -> 505,165 -> 507,165 -> 507,156 -> 507,165 -> 509,165 -> 509,163 -> 509,165 -> 511,165 -> 511,163 -> 511,165 -> 513,165 -> 513,158 -> 513,165 -> 515,165 -> 515,160 -> 515,165 -> 517,165 -> 517,160 -> 517,165 -> 519,165 -> 519,156 -> 519,165
508,70 -> 512,70
486,40 -> 486,44 -> 482,44 -> 482,49 -> 499,49 -> 499,44 -> 491,44 -> 491,40
518,128 -> 518,130 -> 516,130 -> 516,138 -> 525,138 -> 525,130 -> 522,130 -> 522,128
513,141 -> 513,145 -> 512,145 -> 512,152 -> 523,152 -> 523,145 -> 518,145 -> 518,141
495,105 -> 495,99 -> 495,105 -> 497,105 -> 497,97 -> 497,105 -> 499,105 -> 499,103 -> 499,105 -> 501,105 -> 501,102 -> 501,105
485,92 -> 485,89 -> 485,92 -> 487,92 -> 487,84 -> 487,92 -> 489,92 -> 489,89 -> 489,92 -> 491,92 -> 491,88 -> 491,92 -> 493,92 -> 493,85 -> 493,92 -> 495,92 -> 495,82 -> 495,92 -> 497,92 -> 497,91 -> 497,92
500,108 -> 500,112 -> 494,112 -> 494,116 -> 506,116 -> 506,112 -> 505,112 -> 505,108
485,92 -> 485,89 -> 485,92 -> 487,92 -> 487,84 -> 487,92 -> 489,92 -> 489,89 -> 489,92 -> 491,92 -> 491,88 -> 491,92 -> 493,92 -> 493,85 -> 493,92 -> 495,92 -> 495,82 -> 495,92 -> 497,92 -> 497,91 -> 497,92
482,37 -> 482,27 -> 482,37 -> 484,37 -> 484,28 -> 484,37 -> 486,37 -> 486,27 -> 486,37 -> 488,37 -> 488,27 -> 488,37
501,165 -> 501,155 -> 501,165 -> 503,165 -> 503,157 -> 503,165 -> 505,165 -> 505,160 -> 505,165 -> 507,165 -> 507,156 -> 507,165 -> 509,165 -> 509,163 -> 509,165 -> 511,165 -> 511,163 -> 511,165 -> 513,165 -> 513,158 -> 513,165 -> 515,165 -> 515,160 -> 515,165 -> 517,165 -> 517,160 -> 517,165 -> 519,165 -> 519,156 -> 519,165
505,58 -> 510,58
485,92 -> 485,89 -> 485,92 -> 487,92 -> 487,84 -> 487,92 -> 489,92 -> 489,89 -> 489,92 -> 491,92 -> 491,88 -> 491,92 -> 493,92 -> 493,85 -> 493,92 -> 495,92 -> 495,82 -> 495,92 -> 497,92 -> 497,91 -> 497,92
500,108 -> 500,112 -> 494,112 -> 494,116 -> 506,116 -> 506,112 -> 505,112 -> 505,108
486,40 -> 486,44 -> 482,44 -> 482,49 -> 499,49 -> 499,44 -> 491,44 -> 491,40
497,52 -> 502,52
485,92 -> 485,89 -> 485,92 -> 487,92 -> 487,84 -> 487,92 -> 489,92 -> 489,89 -> 489,92 -> 491,92 -> 491,88 -> 491,92 -> 493,92 -> 493,85 -> 493,92 -> 495,92 -> 495,82 -> 495,92 -> 497,92 -> 497,91 -> 497,92
501,165 -> 501,155 -> 501,165 -> 503,165 -> 503,157 -> 503,165 -> 505,165 -> 505,160 -> 505,165 -> 507,165 -> 507,156 -> 507,165 -> 509,165 -> 509,163 -> 509,165 -> 511,165 -> 511,163 -> 511,165 -> 513,165 -> 513,158 -> 513,165 -> 515,165 -> 515,160 -> 515,165 -> 517,165 -> 517,160 -> 517,165 -> 519,165 -> 519,156 -> 519,165
495,105 -> 495,99 -> 495,105 -> 497,105 -> 497,97 -> 497,105 -> 499,105 -> 499,103 -> 499,105 -> 501,105 -> 501,102 -> 501,105
518,128 -> 518,130 -> 516,130 -> 516,138 -> 525,138 -> 525,130 -> 522,130 -> 522,128
487,23 -> 487,24 -> 496,24 -> 496,23
501,165 -> 501,155 -> 501,165 -> 503,165 -> 503,157 -> 503,165 -> 505,165 -> 505,160 -> 505,165 -> 507,165 -> 507,156 -> 507,165 -> 509,165 -> 509,163 -> 509,165 -> 511,165 -> 511,163 -> 511,165 -> 513,165 -> 513,158 -> 513,165 -> 515,165 -> 515,160 -> 515,165 -> 517,165 -> 517,160 -> 517,165 -> 519,165 -> 519,156 -> 519,165
482,37 -> 482,27 -> 482,37 -> 484,37 -> 484,28 -> 484,37 -> 486,37 -> 486,27 -> 486,37 -> 488,37 -> 488,27 -> 488,37
486,40 -> 486,44 -> 482,44 -> 482,49 -> 499,49 -> 499,44 -> 491,44 -> 491,40
482,37 -> 482,27 -> 482,37 -> 484,37 -> 484,28 -> 484,37 -> 486,37 -> 486,27 -> 486,37 -> 488,37 -> 488,27 -> 488,37
499,67 -> 503,67
518,128 -> 518,130 -> 516,130 -> 516,138 -> 525,138 -> 525,130 -> 522,130 -> 522,128
500,108 -> 500,112 -> 494,112 -> 494,116 -> 506,116 -> 506,112 -> 505,112 -> 505,108
501,165 -> 501,155 -> 501,165 -> 503,165 -> 503,157 -> 503,165 -> 505,165 -> 505,160 -> 505,165 -> 507,165 -> 507,156 -> 507,165 -> 509,165 -> 509,163 -> 509,165 -> 511,165 -> 511,163 -> 511,165 -> 513,165 -> 513,158 -> 513,165 -> 515,165 -> 515,160 -> 515,165 -> 517,165 -> 517,160 -> 517,165 -> 519,165 -> 519,156 -> 519,165
501,165 -> 501,155 -> 501,165 -> 503,165 -> 503,157 -> 503,165 -> 505,165 -> 505,160 -> 505,165 -> 507,165 -> 507,156 -> 507,165 -> 509,165 -> 509,163 -> 509,165 -> 511,165 -> 511,163 -> 511,165 -> 513,165 -> 513,158 -> 513,165 -> 515,165 -> 515,160 -> 515,165 -> 517,165 -> 517,160 -> 517,165 -> 519,165 -> 519,156 -> 519,165
485,92 -> 485,89 -> 485,92 -> 487,92 -> 487,84 -> 487,92 -> 489,92 -> 489,89 -> 489,92 -> 491,92 -> 491,88 -> 491,92 -> 493,92 -> 493,85 -> 493,92 -> 495,92 -> 495,82 -> 495,92 -> 497,92 -> 497,91 -> 497,92
501,55 -> 506,55
482,37 -> 482,27 -> 482,37 -> 484,37 -> 484,28 -> 484,37 -> 486,37 -> 486,27 -> 486,37 -> 488,37 -> 488,27 -> 488,37
495,105 -> 495,99 -> 495,105 -> 497,105 -> 497,97 -> 497,105 -> 499,105 -> 499,103 -> 499,105 -> 501,105 -> 501,102 -> 501,105
495,105 -> 495,99 -> 495,105 -> 497,105 -> 497,97 -> 497,105 -> 499,105 -> 499,103 -> 499,105 -> 501,105 -> 501,102 -> 501,105
501,165 -> 501,155 -> 501,165 -> 503,165 -> 503,157 -> 503,165 -> 505,165 -> 505,160 -> 505,165 -> 507,165 -> 507,156 -> 507,165 -> 509,165 -> 509,163 -> 509,165 -> 511,165 -> 511,163 -> 511,165 -> 513,165 -> 513,158 -> 513,165 -> 515,165 -> 515,160 -> 515,165 -> 517,165 -> 517,160 -> 517,165 -> 519,165 -> 519,156 -> 519,165
518,128 -> 518,130 -> 516,130 -> 516,138 -> 525,138 -> 525,130 -> 522,130 -> 522,128
498,15 -> 498,16 -> 508,16 -> 508,15
501,165 -> 501,155 -> 501,165 -> 503,165 -> 503,157 -> 503,165 -> 505,165 -> 505,160 -> 505,165 -> 507,165 -> 507,156 -> 507,165 -> 509,165 -> 509,163 -> 509,165 -> 511,165 -> 511,163 -> 511,165 -> 513,165 -> 513,158 -> 513,165 -> 515,165 -> 515,160 -> 515,165 -> 517,165 -> 517,160 -> 517,165 -> 519,165 -> 519,156 -> 519,165
482,37 -> 482,27 -> 482,37 -> 484,37 -> 484,28 -> 484,37 -> 486,37 -> 486,27 -> 486,37 -> 488,37 -> 488,27 -> 488,37
495,105 -> 495,99 -> 495,105 -> 497,105 -> 497,97 -> 497,105 -> 499,105 -> 499,103 -> 499,105 -> 501,105 -> 501,102 -> 501,105
513,141 -> 513,145 -> 512,145 -> 512,152 -> 523,152 -> 523,145 -> 518,145 -> 518,141
498,15 -> 498,16 -> 508,16 -> 508,15

2
day14/testinput Normal file

@ -0,0 +1,2 @@
498,4 -> 498,6 -> 496,6
503,4 -> 502,4 -> 502,9 -> 494,9

@ -2,6 +2,7 @@ package helper
import (
"constraints"
"errors"
"fmt"
"os"
"strings"
@ -101,3 +102,24 @@ func Remove[T constraints.Ordered](s []T, i int) []T {
s[i] = s[len(s)-1]
return s[:len(s)-1]
}
func GetValueOf2DMap[T any](location [2]int, map2D *[][]T) (T, error) {
if location[0] >= len(*map2D) {
return (*map2D)[0][0], errors.New("First location value too big")
}
if location[1] >= len((*map2D)[location[0]]) {
return (*map2D)[0][0], errors.New("Second location value too big")
}
return (*map2D)[location[0]][location[1]], nil
}
func SetValueOf2DMap[T any](location [2]int, value T, map2D *[][]T) int {
if location[0] >= len(*map2D) {
return -1
}
if location[1] >= len((*map2D)[location[0]]) {
return -1
}
(*map2D)[location[0]][location[1]] = value
return 0
}