Zwischenstand

This commit is contained in:
Karl Spickermann 2022-12-13 21:57:48 +01:00
parent 233513758a
commit dde902d2b4
2 changed files with 16 additions and 13 deletions

@ -12,19 +12,13 @@ func main() {
result := 0
index := 1
for i := 0; i < len(lines); i += 3 {
//fmt.Println(lines[i])
//fmt.Println(lines[i+1])
//fmt.Println(comparePair(lines[i], lines[i+1]))
//fmt.Println()
fmt.Println(lines[i])
fmt.Println(lines[i+1])
fmt.Println(comparePair(lines[i], lines[i+1]))
fmt.Println()
if comparePair(lines[i], lines[i+1]) == 0 {
result += index
}
if comparePair(lines[i], lines[i+1]) == -2 {
fmt.Println(lines[i])
fmt.Println(lines[i+1])
fmt.Println(comparePair(lines[i], lines[i+1]))
fmt.Println()
}
index++
}
@ -36,8 +30,8 @@ func main() {
//-1 Left Value to high
//-2 Right had no values left
func comparePair(left string, right string) int {
lefIndex := -1
rightIndex := -1
lefIndex := 0
rightIndex := 0
currentElemLeft := 0
currentElemRight := 0
leftElementType := 0
@ -58,7 +52,7 @@ func comparePair(left string, right string) int {
if rightElementType == 0 {
for leftElementType != 0 {
lefIndex, leftElementType = getNextElement(left, lefIndex)
if leftElementType == -1 {
if leftElementType == -1 || leftElementType == -3 {
return -2
}
}
@ -92,6 +86,7 @@ func comparePair(left string, right string) int {
//-1 End Packet
//-2 Start Array
//-3 End Array
//-4 Seperator
func getNextElement(packet string, currentIndex int) (int, int) {
index := currentIndex + 1
for index < len(packet) {

8
day13/testinput2 Normal file

@ -0,0 +1,8 @@
[1,2]
[[],2,3]
[[],[8,[[5,10,5]],9]]
[[[[2,8,4],[2,0],4,6,4],2,[[10,5,10],1,[10,9,1,1]]],[2,7],[],[[[3,1,4,8,4],4,[0,5,9,3],4,[]],[],[8,2]]]
[[[],2],[0,6,[[2,7,7,2,4],[7,1]],6,2]]
[[3,[],[[10,2,1,5]]],[]]