From d11426e518c4787d57f38d5138318335ae317f2d Mon Sep 17 00:00:00 2001 From: Davide Oddone Date: Sun, 3 Dec 2023 21:35:05 +0100 Subject: [PATCH] The worst code I've ever written, but somehow it works --- day03/engine-schema.go | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/day03/engine-schema.go b/day03/engine-schema.go index bf9ac47..4d109e1 100644 --- a/day03/engine-schema.go +++ b/day03/engine-schema.go @@ -79,7 +79,6 @@ func main() { } } } - PrintAndWait(totalSum) // Now we loop from 1 to (last index - i) for i := 1; i < len(lines) - 1; i++ { // We need to check the current line against an interval of three lines @@ -89,33 +88,25 @@ func main() { previousLineIndex := resym.FindAllStringIndex(lines[i - 1], -1) currentLineIndex := resym.FindAllStringIndex(lines[i], -1) nextLineIndex := resym.FindAllStringIndex(lines[i + 1], -1) - PrintAndWait("i: ", i) OuterLoop: for k := range currentLineNums { - PrintAndWait("k: ", k, currentLineNums) for j := range previousLineIndex { - PrintAndWait("prev j: ", j, previousLineIndex) if previousLineIndex[j][0] >= currentLineNums[k][0] - 1 && previousLineIndex[j][0] <= currentLineNums[k][1] { - PrintAndWait(numbers[i][k]) totalSum += numbers[i][k] continue OuterLoop } } for j := range currentLineIndex { - PrintAndWait("cur j: ", j, currentLineIndex) if currentLineIndex[j][0] >= currentLineNums[k][0] - 1 && currentLineIndex[j][0] <= currentLineNums[k][1] { - PrintAndWait(numbers[i][k]) totalSum += numbers[i][k] continue OuterLoop } } for j := range nextLineIndex { - PrintAndWait("next j: ", j, nextLineIndex) if nextLineIndex[j][0] >= currentLineNums[k][0] - 1 && nextLineIndex[j][0] <= currentLineNums[k][1] { - PrintAndWait(numbers[i][k]) totalSum += numbers[i][k] continue OuterLoop } @@ -132,26 +123,17 @@ OuterLoop: // a symbol in a specific interval of numbers. If you find a match, you // can break as you just need one symbol for i := range lastLineNums { - PrintAndWait("i: ", i, lastLineNums) for j := range lastLineSymbolsIndex { - PrintAndWait("last j: ", j, notLastLineSymbolsIndex) if lastLineSymbolsIndex[j][0] >= lastLineNums[i][0] - 1 && (lastLineSymbolsIndex[j][0] <= lastLineNums[i][1]) { - PrintAndWait(numbers[len(lines) - 1][i]) - PrintAndWait(totalSum) totalSum += numbers[len(lines) - 1][i] - PrintAndWait(totalSum) break } } for j := range notLastLineSymbolsIndex { - PrintAndWait("notlast j: ", j, notLastLineSymbolsIndex) if (notLastLineSymbolsIndex[j][0] >= lastLineNums[i][0] - 1) && (notLastLineSymbolsIndex[j][0] <= lastLineNums[i][1]) { - PrintAndWait(numbers[len(lines) - 1][i]) - PrintAndWait(totalSum) totalSum += numbers[len(lines) - 1][i] - PrintAndWait(totalSum) break } }