From 2910d6313ccae8f01ff8d1a8799230926593e0eb Mon Sep 17 00:00:00 2001 From: Nico Date: Tue, 2 Dec 2025 00:17:21 +1100 Subject: [PATCH] add aoc 2025 day 1 solution --- 2025/1/README.md | 8 ++++++ 2025/1/input.txt | 10 +++++++ 2025/1/main.go | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 2025/1/README.md create mode 100644 2025/1/input.txt create mode 100644 2025/1/main.go diff --git a/2025/1/README.md b/2025/1/README.md new file mode 100644 index 0000000..42e6015 --- /dev/null +++ b/2025/1/README.md @@ -0,0 +1,8 @@ +# aoc 2025 day 1 + +run with: +```sh +go run main.go +``` + +you will need to put your input into input.txt first though. example is put in input.txt currently diff --git a/2025/1/input.txt b/2025/1/input.txt new file mode 100644 index 0000000..53287c7 --- /dev/null +++ b/2025/1/input.txt @@ -0,0 +1,10 @@ +L68 +L30 +R48 +L5 +R60 +L55 +L1 +L99 +R14 +L82 diff --git a/2025/1/main.go b/2025/1/main.go new file mode 100644 index 0000000..bbb6ee6 --- /dev/null +++ b/2025/1/main.go @@ -0,0 +1,71 @@ +package main + +import ( + "bufio" + "fmt" + "os" + "strconv" + "strings" +) + +func main() { + rotations := Decode("input.txt") + + rotation := 50 + zeroamount := 0 + + for _, i := range rotations { + b := i % 100 // for large number rotations eg. L392 -> L92 + + r := rotation + b + if r > 99 { + r = r - 100 + } else if r < 0 { + r = r + 100 + } + + if r == 0 { + zeroamount = zeroamount + 1 + } + + fmt.Printf("rotation is now at: %d+%d=%d, rotation %d\n", rotation, b, r, i) + rotation = r + } + + fmt.Println("zero amount is:", zeroamount) + +} + +func Decode(filename string) []int { + f, err := os.Open(filename) + + if err != nil { + panic(err) + } + + defer f.Close() + + scanner := bufio.NewScanner(f) + + var rotations []int + + for scanner.Scan() { + if strings.Contains(scanner.Text(), "L") { + a := strings.Replace(scanner.Text(), "L", "", 1) + + b, _ := strconv.Atoi(a) + c := b-b*2 // makes negative, this is so janky + rotations = append(rotations, c) + fmt.Printf("converted %s to int %d\n", scanner.Text(), c) + + } else if strings.Contains(scanner.Text(), "R") { + a := strings.Replace(scanner.Text(), "R", "", 1) + + b, _ := strconv.Atoi(a) + rotations = append(rotations, b) + fmt.Printf("converted %s to int %d\n", scanner.Text(), b) + } + } + + return rotations +}