aoc2023/day-8/one.go

29 lines
440 B
Go
Raw Normal View History

2023-12-08 21:18:51 +00:00
package main
const (
LEFT = iota // 0
RIGHT
)
var directions string
var steps = map[string][]string{}
// one returns the number of steps to reach 'ZZZ'
func one(lines []string) int {
parselines(lines)
num := 0
for i, step := 0, "AAA"; step != "ZZZ"; i, num = i+1, num+1 {
if i == len(directions) {
i = 0
}
if directions[i] == 'L' {
step = steps[step][LEFT]
} else {
step = steps[step][RIGHT]
}
}
return num
}