From 5ce9c707d38a3fddf5ad9c312e38d1f7b943577d Mon Sep 17 00:00:00 2001 From: Nico Date: Fri, 12 Dec 2025 18:04:34 +1100 Subject: [PATCH] add aoc 2025 day 3 solution --- 2025/3/main.go | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 2025/3/main.go diff --git a/2025/3/main.go b/2025/3/main.go new file mode 100644 index 0000000..0893df8 --- /dev/null +++ b/2025/3/main.go @@ -0,0 +1,65 @@ +package main + +import ( + "bufio" + "fmt" + "os" + "strconv" +) + +func main() { + // iterate over all IDs + joltages := Decode("input.txt") + + var joltagessum int = 0 + + for _, i := range joltages { + var tensColumn int = 0 + var onesColumn int = 0 + + for iteration, x := range i { + num, err := strconv.Atoi(string(x)) + if err != nil { + panic(err) + } + + if tensColumn == 0 { + tensColumn = num + } else if num > tensColumn && iteration != len(i)-1 { + tensColumn = num + onesColumn = 0 + } else if num > onesColumn && onesColumn >= tensColumn { + tensColumn = onesColumn + onesColumn = num + } else if num > onesColumn { + onesColumn = num + } + } + + sum := tensColumn*10 + onesColumn + fmt.Printf("joltage found for %s, %d%d %d\n", i, tensColumn, onesColumn, sum) + joltagessum = joltagessum + sum + } + + fmt.Println("total joltage sum", joltagessum) +} + +func Decode(filename string) []string { + f, err := os.Open(filename) + + if err != nil { + panic(err) + } + + defer f.Close() + + scanner := bufio.NewScanner(f) + var joltages []string + + for scanner.Scan() { + // extract joltage numbers into struct to go over + joltages = append(joltages, scanner.Text()) + } + + return joltages +}