Compare commits

..

2 commits

2 changed files with 64 additions and 0 deletions

3
2025/go.mod Normal file
View file

@ -0,0 +1,3 @@
module forgejo.gwairfelin.com/aoc
go 1.25.4

61
2025/one.go Normal file
View file

@ -0,0 +1,61 @@
package main
import (
"bufio"
"log"
"os"
"strconv"
)
func mod(a int, b int) int {
return (a%b + b) % b
}
func One() {
cur := 50
n_zeroes := 0
file, err := os.Open("one.txt")
if err != nil {
log.Fatal(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
text := scanner.Text()
num, err := strconv.Atoi(text[1:])
if err != nil {
log.Fatal(err)
}
var next_pre_modulo int = 0
if text[0] == 'R' {
next_pre_modulo = cur + num
n_zeroes += next_pre_modulo / 100
} else {
next_pre_modulo = cur - num
if next_pre_modulo <= 0 {
extra := (next_pre_modulo / -100)
// Omg you sneaky fuck! We only add one if we didn't start on
// 0 already.
if cur != 0 {
extra += 1
}
n_zeroes += extra
}
}
cur = mod(next_pre_modulo, 100)
log.Printf("Next pre mod: %d, post mod: %d, n zeroes: %d", next_pre_modulo, cur, n_zeroes)
}
}
func main() {
One()
}