From dde902d2b448227ba52bc92af902a8d714153260 Mon Sep 17 00:00:00 2001 From: Karl Spickermann Date: Tue, 13 Dec 2022 21:57:48 +0100 Subject: [PATCH] Zwischenstand --- day13/day13.go | 21 ++++++++------------- day13/testinput2 | 8 ++++++++ 2 files changed, 16 insertions(+), 13 deletions(-) create mode 100644 day13/testinput2 diff --git a/day13/day13.go b/day13/day13.go index 4167f85..d3b88ab 100644 --- a/day13/day13.go +++ b/day13/day13.go @@ -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) { diff --git a/day13/testinput2 b/day13/testinput2 new file mode 100644 index 0000000..d932761 --- /dev/null +++ b/day13/testinput2 @@ -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]]],[]]