add aoc 2025 day 1 solution

This commit is contained in:
Nico 2025-12-02 00:17:21 +11:00
parent 32d8142420
commit 2910d6313c
Signed by: nico
SSH key fingerprint: SHA256:XuacYOrGqRxC3jVFjfLROn1CSvLz85Dec6N7O9Gwu/0
3 changed files with 89 additions and 0 deletions

71
2025/1/main.go Normal file
View file

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