瀏覽代碼

day 6 part 1

Abderrahmane Faiz 2 周之前
父節點
當前提交
13899cb69a
共有 4 個文件被更改,包括 69 次插入1 次删除
  1. 1 0
      1/solve_1.go
  2. 1 0
      1/solve_2.go
  3. 66 0
      6/solve_1.go
  4. 1 1
      README.md

+ 1 - 0
1/solve_1.go

@@ -9,6 +9,7 @@ import (
 )
 
 func main() {
+	fmt.Println("Advent of Code 2025 - Day 1 - Part 1")
 	nb_occ_zero := 0
 	lock_num := 50
 	direction := 1

+ 1 - 0
1/solve_2.go

@@ -10,6 +10,7 @@ import (
 )
 
 func main() {
+	fmt.Println("Advent of Code 2025 - Day 1 - Part 2")
 	nb_occ_zero, lock_num := 0, 50
 	var direction, nb_ticks, prev_lock_num, nb_cycles int
 	var instruction string

+ 66 - 0
6/solve_1.go

@@ -0,0 +1,66 @@
+package main
+
+import (
+	"bufio"
+	"fmt"
+	"os"
+	"strconv"
+	"strings"
+)
+
+func main(){
+	fmt.Println("Advent of Code 2025 - Day 6 - Part 1")
+	f,_:=os.Open("6/input")
+	defer f.Close()
+	scanner:=bufio.NewScanner(f)
+	var grid [][]string
+	for scanner.Scan(){
+		line:= scanner.Text()
+		var operands []string
+		for op := range strings.SplitSeq(line," ") {
+			if (len(op) > 0){
+				operands = append(operands, op)
+			}
+		}
+		grid = append(grid, operands)
+	}
+	
+	operators := grid[len(grid)-1]
+	operands_matrix := grid[:len(grid)-1]
+	n := len(operands_matrix)
+	m := len(operands_matrix[0])
+	
+	transpose_operands_matrix := make([][]string, m)
+	for j:= range m{
+		transpose_operands_matrix[j] = make([]string, n)
+		for i:= range n{
+			transpose_operands_matrix[j][i] = operands_matrix[i][j]
+		}
+	}
+
+	res := int64(0)
+	for i,operation:= range transpose_operands_matrix {
+		res += calculate(operators[i], operation)
+	}
+	fmt.Println(res)
+}
+
+
+func calculate(operator string, operands []string) int64{
+	var res int64
+	switch(operator){
+		case "*":
+		res = int64(1)
+		for _,op := range operands{
+			op_toi,_ := strconv.ParseInt(op,10,64) 
+			res *= op_toi
+		}
+		case "+":
+		res = int64(0)
+		for _,op := range operands{
+			op_toi,_ := strconv.ParseInt(op,10,64) 
+			res += op_toi
+		}
+	}
+	return res
+}

+ 1 - 1
README.md

@@ -25,7 +25,7 @@ Each day's folder is named after the day number (`1` to `12`). Inside each folde
 | 3   | ✅     | ✅     |
 | 4   | ✅     | ✅     |
 | 5   | ✅     | ✅     |
-| 6   |      | ⬜     |
+| 6   |      | ⬜     |
 | 7   | ⬜     | ⬜     |
 | 8   | ⬜     | ⬜     |
 | 9   | ⬜     | ⬜     |