Browse Source

Solved part1

Piotr Czajkowski 1 week ago
parent
commit
a8a4d07d51
2 changed files with 23 additions and 1 deletions
  1. 23 1
      06/code.go
  2. 0 0
      06/input

+ 23 - 1
06/code.go

@@ -52,6 +52,28 @@ func readInput(file *os.File) ([][]int, []string) {
 	return numbers, symbols
 }
 
+func part1(numbers [][]int, symbols []string) int {
+	var sum int
+
+	for i, symbol := range symbols {
+		var result int
+		for row := range numbers {
+			if symbol == "+" {
+				result += numbers[row][i]
+			} else if symbol == "*" {
+				if result == 0 {
+					result = 1
+				}
+				result *= numbers[row][i]
+			}
+		}
+
+		sum += result
+	}
+
+	return sum
+}
+
 func main() {
 	if len(os.Args) < 2 {
 		log.Fatal("You need to specify a file!")
@@ -64,5 +86,5 @@ func main() {
 	}
 
 	numbers, symbols := readInput(file)
-	fmt.Println(numbers, symbols)
+	fmt.Println("Part1:", part1(numbers, symbols))
 }

File diff suppressed because it is too large
+ 0 - 0
06/input


Some files were not shown because too many files changed in this diff