day 01
This commit is contained in:
3
01/go.mod
Normal file
3
01/go.mod
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module git.z1glr.de/advent-of-code-2025/01
|
||||||
|
|
||||||
|
go 1.25.4
|
||||||
54
01/main.go
Normal file
54
01/main.go
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
if bytes, err := os.ReadFile("input"); err != nil {
|
||||||
|
panic(err)
|
||||||
|
} else {
|
||||||
|
content := strings.TrimSpace(string(bytes))
|
||||||
|
|
||||||
|
turns := strings.SplitSeq(content, "\n")
|
||||||
|
|
||||||
|
position := 50
|
||||||
|
zeroCount := 0
|
||||||
|
|
||||||
|
zeroPasses := 0
|
||||||
|
|
||||||
|
for turn := range turns {
|
||||||
|
left := turn[0] == 'L'
|
||||||
|
|
||||||
|
if steps, err := strconv.Atoi(strings.TrimSpace(turn[1:])); err != nil {
|
||||||
|
panic(err)
|
||||||
|
} else {
|
||||||
|
for range steps {
|
||||||
|
if left {
|
||||||
|
position--
|
||||||
|
} else {
|
||||||
|
position++
|
||||||
|
}
|
||||||
|
|
||||||
|
position = (position + 100) % 100
|
||||||
|
|
||||||
|
if position == 0 {
|
||||||
|
zeroPasses++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if position == 0 {
|
||||||
|
zeroCount++
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(zeroCount)
|
||||||
|
fmt.Println(zeroPasses)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user