| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- 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
- }
|